d = 666
def default_due(a, b=d):
print('a =', a, 'b =', b)
d = 0
default_due(11)
default_due(22,33)
I don't understand why this prints
a = 11 b = 666
a = 22 b = 33
And not
a = 11 b = 0
a = 22 b = 33
d = 666
def default_due(a, b=d):
print('a =', a, 'b =', b)
d = 0
default_due(11)
default_due(22,33)
I don't understand why this prints
a = 11 b = 666
a = 22 b = 33
And not
a = 11 b = 0
a = 22 b = 33
As you are not passing the value for the second parameter, the default value is used. But, in the second case, when the value for second parameter is also passed, then the default value is overridden with the new value. Hence, this results in the output you've observed. You can even verify the results.
For more detailed explaination, see this: