0
def fn(a=55,b):
    print(a,b)

fn(1,2)

This is a python code. After running this error occurred:

SyntaxError: non-default argument follows default argument
1

1 Answer 1

0

In the function definition, default arguments come after non-default arguments. You can read more about Function Definitions in Python Docs:

When one or more parameters have the form parameter = expression, the function is said to have default parameter values. For a parameter with a default value, the corresponding argument may be omitted from a call, in which case the parameter’s default value is substituted. If a parameter has a default value, all following parameters up until the * must also have a default value — this is a syntactic restriction that is not expressed by the grammar.


In your case, b (non-default) must be defined prior to a=55 (default).

def fn(b, a=55):
    print(a, b)

fn(1, 2)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.