from os import system def a(len1,hgt=len1,til,col=0): system('mode con cols='+len1,'lines='+hgt) system('title',til) system('color',col) a(64,25,"hi","0b") input()
When I run this, it rejects "def a(..." and highlights "(" in red. I have no clue why.
The error “SyntaxError: non-default argument follows default argument” occurs when you specify a default argument before a non-default argument. To solve this error, ensure that you arrange all arguments in your function definition such that the default arguments come after the non-default arguments.
Since Python interprets positional arguments in the order in which they appear first and then followed by the keyword arguments as next. We can resolve the SyntaxError by providing all the positional arguments first, followed by the keyword arguments at last.
Default arguments in Python functions are those arguments that take default values if no explicit values are passed to these arguments from the function call.
Python allows function arguments to have default values. If the function is called without the argument, the argument gets its default value.
Let me clarify two points here :
(a = 'b',c)
in function. The correct order of defining parameter in function are :(a,b,c)
(a = 'b',r= 'j')
(*args)
(**kwargs)
def example(a, b, c=None, r="w" , d=[], *ae, **ab):
(a,b)
are positional parameter
(c=none)
is optional parameter
(r="w")
is keyword parameter
(d=[])
is list parameter
(*ae)
is keyword-only
(*ab)
is var-keyword parameter
so first re-arrange your parameters
so second remove this "len1 = hgt"
it's not allowed in python.
keep in mind the difference between argument and parameters.
As the error message says, non-default argument til
should not follow default argument hgt
.
Changing order of parameters (function call also be adjusted accordingly) or making hgt
non-default parameter will solve your problem.
def a(len1, hgt=len1, til, col=0):
->
def a(len1, hgt, til, col=0):
UPDATE
Another issue that is hidden by the SyntaxError.
os.system
accepts only one string parameter.
def a(len1, hgt, til, col=0): system('mode con cols=%s lines=%s' % (len1, hgt)) system('title %s' % til) system('color %s' % col)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With