Quote:
|
Originally Posted by titaniumdecoy
Yes, but why doesn't curr behave like a static variable when it is not a list?
|
Because in your case the variable would be immutable, simply an integer.
To follow this up with an example:
# Python's version of a static variable
def static_num(list1=[0]):
"""The function's default is a list with one element = zero.
Since the list is a mutable object it retains its address,
as the function's default is created at compile time.
Whatever you put into this list as element is retained too"""
list1[0] += 1
return list1[0]
print static_num() # 1
print static_num() # 2
print static_num() # 3
... Well, not quite the same beast! Maybe Sane can help!