What should the following code print?
class C:
def b(self,d = {'k':0}):
print(d)
d['k'] += 1
def a(self):
self.b()
c1 = C()
for i in range(3):
c1.a()
I could have sworn it should be
{'k': 0}
{'k': 0}
{'k': 0}
since I am calling b self.b() without any parameters so it should pick the default value of d each time which is {'k':0}. I just don't know what I am overlooking here but it prints
{'k': 0}
{'k': 1}
{'k': 2}
What is wrong with the following two statements?
- It should pick the default value of
dwhenbis called without arguments dshould be local to the methodband should not persist between different calls to the methodb