Python function with default argument inside loop -
for in range(5): def test(i=i): print(i) test() test() test() test() test()
this prints 4 every time? can me understanding this.
you redefine test
4 times:
same as:
#define test def test(i = 0): print(i) #redefine test def test(i = 1): print(i) #redefine test def test(i = 2): print(i) #redefine test def test(i = 3): print(i) #redefine test def test(i = 4): print(i)
so have 1 test()
last one.
Comments
Post a Comment