static variable in python

def fun(L=[0]):
L[0]+=1
return L[0]
print fun(),fun(),fun(),fun() # will produce 1 2 3 4

this use the default variable.
the default variable value should be a list.


def fun(L=[0]):
L[0]+=1
return L[0]
print fun(),fun(),fun(),fun() # will produce 1 2 3 4

this use the default variable.
the default variable value should be a list.

Leave a Reply

Your email address will not be published. Required fields are marked *