Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

count variable in class python

class Car:
  counter = 0
  def __init__(self,color):
    self.color = color
   	Car.counter += 1

car1 = Car("red")
car2 = Car("orange")
print(Car.counter)
 
PREVIOUS NEXT
Tagged: #count #variable #class #python
ADD COMMENT
Topic
Name
2+9 =