Positional argument follows keyword argument | Error while calling function












0















First, I understand that while defining function you have to place positional arguments first and then default arguments to avoid the ambiguity situation for interpreter. That is why when we try to do it, it throws an error.



For e.g. in the following code, a and b cannot be evaluated at the runtime due to which it throws an error



def func(a=1,b):
return a+b

func(2)


(Error:non-default argument follows default argument)



This is understandable.



But why does the following results in an error. It does not occur at the time of defining function but at the time of calling function.



def student(firstname, standard,lastname): 
print(firstname, lastname, 'studies in', standard, 'Standard')
student(firstname ='John','Gates','Seventh')

Error:positional argument follows keyword argument


Can't we pass parameters with and without keywords simultaneously?
[Edit]: The question is not a possible duplicates as the duplicates talk about the case when default arguments are defines. I've not defined them. I am just asking why can't we mix keyword value parameters and direct value parameters.










share|improve this question

























  • Possible duplicate of positional argument follows keyword argument

    – Abdul Niyas P M
    Nov 21 '18 at 9:14
















0















First, I understand that while defining function you have to place positional arguments first and then default arguments to avoid the ambiguity situation for interpreter. That is why when we try to do it, it throws an error.



For e.g. in the following code, a and b cannot be evaluated at the runtime due to which it throws an error



def func(a=1,b):
return a+b

func(2)


(Error:non-default argument follows default argument)



This is understandable.



But why does the following results in an error. It does not occur at the time of defining function but at the time of calling function.



def student(firstname, standard,lastname): 
print(firstname, lastname, 'studies in', standard, 'Standard')
student(firstname ='John','Gates','Seventh')

Error:positional argument follows keyword argument


Can't we pass parameters with and without keywords simultaneously?
[Edit]: The question is not a possible duplicates as the duplicates talk about the case when default arguments are defines. I've not defined them. I am just asking why can't we mix keyword value parameters and direct value parameters.










share|improve this question

























  • Possible duplicate of positional argument follows keyword argument

    – Abdul Niyas P M
    Nov 21 '18 at 9:14














0












0








0








First, I understand that while defining function you have to place positional arguments first and then default arguments to avoid the ambiguity situation for interpreter. That is why when we try to do it, it throws an error.



For e.g. in the following code, a and b cannot be evaluated at the runtime due to which it throws an error



def func(a=1,b):
return a+b

func(2)


(Error:non-default argument follows default argument)



This is understandable.



But why does the following results in an error. It does not occur at the time of defining function but at the time of calling function.



def student(firstname, standard,lastname): 
print(firstname, lastname, 'studies in', standard, 'Standard')
student(firstname ='John','Gates','Seventh')

Error:positional argument follows keyword argument


Can't we pass parameters with and without keywords simultaneously?
[Edit]: The question is not a possible duplicates as the duplicates talk about the case when default arguments are defines. I've not defined them. I am just asking why can't we mix keyword value parameters and direct value parameters.










share|improve this question
















First, I understand that while defining function you have to place positional arguments first and then default arguments to avoid the ambiguity situation for interpreter. That is why when we try to do it, it throws an error.



For e.g. in the following code, a and b cannot be evaluated at the runtime due to which it throws an error



def func(a=1,b):
return a+b

func(2)


(Error:non-default argument follows default argument)



This is understandable.



But why does the following results in an error. It does not occur at the time of defining function but at the time of calling function.



def student(firstname, standard,lastname): 
print(firstname, lastname, 'studies in', standard, 'Standard')
student(firstname ='John','Gates','Seventh')

Error:positional argument follows keyword argument


Can't we pass parameters with and without keywords simultaneously?
[Edit]: The question is not a possible duplicates as the duplicates talk about the case when default arguments are defines. I've not defined them. I am just asking why can't we mix keyword value parameters and direct value parameters.







python parameters arguments keyword-argument positional-parameter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 9:26







pragun

















asked Nov 21 '18 at 9:04









pragunpragun

746




746













  • Possible duplicate of positional argument follows keyword argument

    – Abdul Niyas P M
    Nov 21 '18 at 9:14



















  • Possible duplicate of positional argument follows keyword argument

    – Abdul Niyas P M
    Nov 21 '18 at 9:14

















Possible duplicate of positional argument follows keyword argument

– Abdul Niyas P M
Nov 21 '18 at 9:14





Possible duplicate of positional argument follows keyword argument

– Abdul Niyas P M
Nov 21 '18 at 9:14












2 Answers
2






active

oldest

votes


















0














Maybe You should try :



student('John', 'Gates', 'Stevehn')


I dont know if you can define a variable in same time as calling a function.



Sydney






share|improve this answer
























  • I am not defining variables while calling function. you can certainly do something like this student(firstname ='John',standard='Seventh',lastname='Gates'). Here order does not matter.

    – pragun
    Nov 21 '18 at 9:20





















0














It's exactly as the error says:



Error:positional argument follows keyword argument


You can't have positional arguments following keyword arguments.



Your example is a good case in point.



You specify the first argument as a keyword argument. So it's ambiguous how the interpreter is to interpret the order of parameters now. Does the 2nd argument become the first parameter? The second parameter? But you've already specified the first parameter (firstname='John') so what happens to the positional parameter?



def student(firstname, standard,lastname):
print(firstname, lastname, 'studies in', standard, 'Standard')



student(firstname ='John','Gates','Seventh')


Does the interpret interpret this as:



student(firstname ='John',standard='Gates',lastname='Seventh')


or



student(firstname ='John',standard='Gates',lastname='Seventh')


or



student(firstname ='John',firstname='Gates',lastname='Seventh')


What about:



student(lastname ='John','Gates','Seventh')


This?



student(lastname ='John',firstname='Gates',standard='Seventh')


or this?



student(lastname ='John',standard='Gates',firstname='Seventh')


Good luck trying to debug what argument matches what parameter.






share|improve this answer


























  • while calling functions too? I understand it is the case while defining functions. but here there is no ambiguity.

    – pragun
    Nov 21 '18 at 9:23











  • @pragun updated with examples

    – richflow
    Nov 21 '18 at 9:32











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408497%2fpositional-argument-follows-keyword-argument-error-while-calling-function%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Maybe You should try :



student('John', 'Gates', 'Stevehn')


I dont know if you can define a variable in same time as calling a function.



Sydney






share|improve this answer
























  • I am not defining variables while calling function. you can certainly do something like this student(firstname ='John',standard='Seventh',lastname='Gates'). Here order does not matter.

    – pragun
    Nov 21 '18 at 9:20


















0














Maybe You should try :



student('John', 'Gates', 'Stevehn')


I dont know if you can define a variable in same time as calling a function.



Sydney






share|improve this answer
























  • I am not defining variables while calling function. you can certainly do something like this student(firstname ='John',standard='Seventh',lastname='Gates'). Here order does not matter.

    – pragun
    Nov 21 '18 at 9:20
















0












0








0







Maybe You should try :



student('John', 'Gates', 'Stevehn')


I dont know if you can define a variable in same time as calling a function.



Sydney






share|improve this answer













Maybe You should try :



student('John', 'Gates', 'Stevehn')


I dont know if you can define a variable in same time as calling a function.



Sydney







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 9:13









Alwin4youAlwin4you

32




32













  • I am not defining variables while calling function. you can certainly do something like this student(firstname ='John',standard='Seventh',lastname='Gates'). Here order does not matter.

    – pragun
    Nov 21 '18 at 9:20





















  • I am not defining variables while calling function. you can certainly do something like this student(firstname ='John',standard='Seventh',lastname='Gates'). Here order does not matter.

    – pragun
    Nov 21 '18 at 9:20



















I am not defining variables while calling function. you can certainly do something like this student(firstname ='John',standard='Seventh',lastname='Gates'). Here order does not matter.

– pragun
Nov 21 '18 at 9:20







I am not defining variables while calling function. you can certainly do something like this student(firstname ='John',standard='Seventh',lastname='Gates'). Here order does not matter.

– pragun
Nov 21 '18 at 9:20















0














It's exactly as the error says:



Error:positional argument follows keyword argument


You can't have positional arguments following keyword arguments.



Your example is a good case in point.



You specify the first argument as a keyword argument. So it's ambiguous how the interpreter is to interpret the order of parameters now. Does the 2nd argument become the first parameter? The second parameter? But you've already specified the first parameter (firstname='John') so what happens to the positional parameter?



def student(firstname, standard,lastname):
print(firstname, lastname, 'studies in', standard, 'Standard')



student(firstname ='John','Gates','Seventh')


Does the interpret interpret this as:



student(firstname ='John',standard='Gates',lastname='Seventh')


or



student(firstname ='John',standard='Gates',lastname='Seventh')


or



student(firstname ='John',firstname='Gates',lastname='Seventh')


What about:



student(lastname ='John','Gates','Seventh')


This?



student(lastname ='John',firstname='Gates',standard='Seventh')


or this?



student(lastname ='John',standard='Gates',firstname='Seventh')


Good luck trying to debug what argument matches what parameter.






share|improve this answer


























  • while calling functions too? I understand it is the case while defining functions. but here there is no ambiguity.

    – pragun
    Nov 21 '18 at 9:23











  • @pragun updated with examples

    – richflow
    Nov 21 '18 at 9:32
















0














It's exactly as the error says:



Error:positional argument follows keyword argument


You can't have positional arguments following keyword arguments.



Your example is a good case in point.



You specify the first argument as a keyword argument. So it's ambiguous how the interpreter is to interpret the order of parameters now. Does the 2nd argument become the first parameter? The second parameter? But you've already specified the first parameter (firstname='John') so what happens to the positional parameter?



def student(firstname, standard,lastname):
print(firstname, lastname, 'studies in', standard, 'Standard')



student(firstname ='John','Gates','Seventh')


Does the interpret interpret this as:



student(firstname ='John',standard='Gates',lastname='Seventh')


or



student(firstname ='John',standard='Gates',lastname='Seventh')


or



student(firstname ='John',firstname='Gates',lastname='Seventh')


What about:



student(lastname ='John','Gates','Seventh')


This?



student(lastname ='John',firstname='Gates',standard='Seventh')


or this?



student(lastname ='John',standard='Gates',firstname='Seventh')


Good luck trying to debug what argument matches what parameter.






share|improve this answer


























  • while calling functions too? I understand it is the case while defining functions. but here there is no ambiguity.

    – pragun
    Nov 21 '18 at 9:23











  • @pragun updated with examples

    – richflow
    Nov 21 '18 at 9:32














0












0








0







It's exactly as the error says:



Error:positional argument follows keyword argument


You can't have positional arguments following keyword arguments.



Your example is a good case in point.



You specify the first argument as a keyword argument. So it's ambiguous how the interpreter is to interpret the order of parameters now. Does the 2nd argument become the first parameter? The second parameter? But you've already specified the first parameter (firstname='John') so what happens to the positional parameter?



def student(firstname, standard,lastname):
print(firstname, lastname, 'studies in', standard, 'Standard')



student(firstname ='John','Gates','Seventh')


Does the interpret interpret this as:



student(firstname ='John',standard='Gates',lastname='Seventh')


or



student(firstname ='John',standard='Gates',lastname='Seventh')


or



student(firstname ='John',firstname='Gates',lastname='Seventh')


What about:



student(lastname ='John','Gates','Seventh')


This?



student(lastname ='John',firstname='Gates',standard='Seventh')


or this?



student(lastname ='John',standard='Gates',firstname='Seventh')


Good luck trying to debug what argument matches what parameter.






share|improve this answer















It's exactly as the error says:



Error:positional argument follows keyword argument


You can't have positional arguments following keyword arguments.



Your example is a good case in point.



You specify the first argument as a keyword argument. So it's ambiguous how the interpreter is to interpret the order of parameters now. Does the 2nd argument become the first parameter? The second parameter? But you've already specified the first parameter (firstname='John') so what happens to the positional parameter?



def student(firstname, standard,lastname):
print(firstname, lastname, 'studies in', standard, 'Standard')



student(firstname ='John','Gates','Seventh')


Does the interpret interpret this as:



student(firstname ='John',standard='Gates',lastname='Seventh')


or



student(firstname ='John',standard='Gates',lastname='Seventh')


or



student(firstname ='John',firstname='Gates',lastname='Seventh')


What about:



student(lastname ='John','Gates','Seventh')


This?



student(lastname ='John',firstname='Gates',standard='Seventh')


or this?



student(lastname ='John',standard='Gates',firstname='Seventh')


Good luck trying to debug what argument matches what parameter.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 9:31

























answered Nov 21 '18 at 9:11









richflowrichflow

881210




881210













  • while calling functions too? I understand it is the case while defining functions. but here there is no ambiguity.

    – pragun
    Nov 21 '18 at 9:23











  • @pragun updated with examples

    – richflow
    Nov 21 '18 at 9:32



















  • while calling functions too? I understand it is the case while defining functions. but here there is no ambiguity.

    – pragun
    Nov 21 '18 at 9:23











  • @pragun updated with examples

    – richflow
    Nov 21 '18 at 9:32

















while calling functions too? I understand it is the case while defining functions. but here there is no ambiguity.

– pragun
Nov 21 '18 at 9:23





while calling functions too? I understand it is the case while defining functions. but here there is no ambiguity.

– pragun
Nov 21 '18 at 9:23













@pragun updated with examples

– richflow
Nov 21 '18 at 9:32





@pragun updated with examples

– richflow
Nov 21 '18 at 9:32


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408497%2fpositional-argument-follows-keyword-argument-error-while-calling-function%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

Npm cannot find a required file even through it is in the searched directory