First of all I'm new to python so this is kinda confusing to me. I come from c++ background and there is nothing similar to this. I tried to google it but I don't even know how to call it.
I found this code where there seems to be some sort of variable bound to the function name like an object or something and I don't understand what it is and how it works and how is supposed to be used.
def foo():
foo.counter+=1
foo.counter=0
foo()
print(foo.counter)
Now if I remove the foo. prefix, the program stops working.
However, if I add global declaration, it works again:
def foo():
global counter
counter+=1
counter=0
foo()
print(counter)
So my question is what exactly is that foo. prefix and what does it do ?