scientific_comp_projects/CODE/[python]object_oriented(tech_with_tim)/person.py

30 lines
528 B
Python
Raw Normal View History

2021-10-29 15:16:40 +02:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class Person:
# Class attributes
# the same for everyone.
number_of_people = 0
def __init__(self, name):
self.name = name
#Person.number_of_people += 1
Person.add_person()
@classmethod
def number_of_people_(cls):
return cls.number_of_people
@classmethod
def add_person(cls):
cls.number_of_people += 1
p1 = Person('tim')
p2 = Person('jill')
print(p2.number_of_people)
print(Person.number_of_people_())