I was just playing around testing if strings were immutable because I was a bit tired :D and made this
def x(string = "a", y = 0):
if y == 5:
return
else:
string += "x"
print(string)
x(string, y = y + 1)
print(string)
x()
and I am simply wondering why this works but
def x(string = "a", y = 0):
if y == 5:
return
else:
string += "x"
print(string)
x(string, y += 1)
print(string)
x()
Does not work (The difference in the y variable assignment in the recursive call). Why is it a syntax error, theyre simply doing the same thing?
yafter the recursive call tox()and you will find it hasn't changed. You are using the keyword argynot assignment toyin yourx()function call.