30 lines
528 B
Python
30 lines
528 B
Python
|
#!/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_())
|
||
|
|
||
|
|
||
|
|