-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasicClassPython.py
60 lines (45 loc) · 1.81 KB
/
BasicClassPython.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#! /usr/bin/env/python
#-------------------------------------------------------------------------------------------
# Class 1
#-------------------------------------------------------------------------------------------
class Employee:
'Employee Generic Class'
# This is like a Static Variables that counts all employees
numEmployees = 0
def __init__(self, name, age = 1):
self.name = name
self.age = age
# NumEmployees can be accessed only through Employee
Employee.numEmployees += 1
def getEmployeesCount(self):
print("Number of People: ", Employee.numEmployees)
return Employee.numEmployees
def printEmployee(self):
print("Name: %s, Age: %d" % (self.name, self.age))
#-------------------------------------------------------------------------------------------
# Class 2
#-------------------------------------------------------------------------------------------
class Shapes:
'Shapes Generic Class'
# This is like a Static Variables that counts all shapes
numShapes = 0
#-------------------------------------------------------------------------------------------
# Main Function
#-------------------------------------------------------------------------------------------
def main():
print("Basic Class")
#Employee Example
emp1 = Employee("abc", 23)
emp2 = Employee("def", 34)
emp3 = Employee("qwe", 98)
# Calling with Default AGE
emp4 = Employee("qwe")
empList = [emp1, emp2, emp3, emp4]
print(Employee.numEmployees)
for emp in empList:
emp.printEmployee()
#-------------------------------------------------------------------------------------------
# Start Main
#-------------------------------------------------------------------------------------------
if __name__ == "__main__":
main()