-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.py
More file actions
32 lines (27 loc) · 855 Bytes
/
object.py
File metadata and controls
32 lines (27 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#! /usr/bin/python
# Filename object.python
# Description: user of object variable and class variables
class Person:
population = 0
def __init__(self, name):
self.name = name
Person.population += 1 # Note: must using Person.population
print "My name is %s" % self.name
def __del__(self):
Person.population -= 1
print "%s say goodbye" % self.name
if Person.population == 0:
print "I am the last one"
else:
print "the population is ", Person.population
def sayHi(self):
print "Hi, I am %s" % self.name
print "Population is %d" % Person.population
def howmany(self):
print "The current population is ", Person.population
test1 = Person("test1")
test1.sayHi()
test1.howmany()
test2 = Person("test2")
test2.sayHi()
test2.howmany()