-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathprog27_OOPS_class_objects.py
55 lines (38 loc) · 1.13 KB
/
prog27_OOPS_class_objects.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
'''
Concept of OOPS:
Abstraction
Encapsulation
Inheritance
Polymorphism
'''
# ---------- Example -1 ---------------------------------
# Understand class and instance
# class Student:
# pass
# harry = Student() # first instance of class student
# marry = Student() # second instance of class student
# # print(harry, marry)
# harry.name = "Harry Kumar"
# harry.age = 32
# marry.name = "Marry John"
# marry.subject = ["Physics", "Chemistry", "Math"]
# print(harry.name, marry.subject)
# ---------- Example -2 ---------------------------------
class Employee:
no_of_leaves = 12
pass
ram = Employee()
joel = Employee()
ram.name = "Ram Krishna"
ram.salary = 40000
joel.name = "Joel F."
joel.salary = 41000
print(ram.name, joel.name)
print(ram.no_of_leaves)
print(joel.no_of_leaves)
ram.no_of_leaves = 20 # It will create a new variable for this instance. Can not change the value of class's variables by other instance.
print(ram.__dict__)
print(joel.__dict__)
print(Employee.__dict__)
Employee.no_of_leaves = 15 # Change the value of class's variables
print(Employee.__dict__)