I am new to Python, and I have one dilemma concerning OOP (I am familiar with OOP concepts).
Basically, I have a class with a static class-variable (counter that shows how many objects I have instantiated):
class Employee:
counter=0
def __init__(self,name):
self.name=name
Employee.counter+=1
So now I instantiate an object:
obj1=Employee("Alan")
My question is: what happens when I have this call? What happens behind, because the static variable "counter" is incremented, but it is possible to access the object created like this?
Employee("foo")
<__main__.Employee object at 0x02A16870>
Thanks
__init__function is your constructor, so it incrementscounterwhenever you create a new `Employee object. What exactly are you asking?countershould be accessed via the instance or classcounter += 1should beEmployee.counter += 1.