The error says 'non-default argument follows default argument' | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

The error says 'non-default argument follows default argument'

def f(x,y,z='spam',a): print(z) f(1,2,'hello',5)

19th Apr 2019, 12:42 AM
Thimira Rathnayake
Thimira Rathnayake - avatar
6 Answers
+ 5
Yes 'cause you can't have non-default args after defaults. def(x,y,a, z='spam'): print(z) is the correct way.
19th Apr 2019, 12:57 AM
Шащи Ранжан
Шащи Ранжан - avatar
+ 2
From the error, I would assume that you should keep all parameters for your function with a default value at the end as to avoid raising the error again. It should be something like this: def f(x,y,a,z="spam"): # Code
19th Apr 2019, 12:57 AM
Faisal
Faisal - avatar
+ 2
def f(x,y,a,z='spam'): print(z) f(1,2,5,'hello')
19th Apr 2019, 12:57 AM
Solo
Solo - avatar
+ 1
Thanks Vasiliy
19th Apr 2019, 1:00 AM
Thimira Rathnayake
Thimira Rathnayake - avatar
0
Thanks M.Watney
19th Apr 2019, 12:59 AM
Thimira Rathnayake
Thimira Rathnayake - avatar
0
Thanks Faisal
19th Apr 2019, 12:59 AM
Thimira Rathnayake
Thimira Rathnayake - avatar