Skip to content

Commit c52c41c

Browse files
authored
Add files via upload
0 parents  commit c52c41c

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

oop.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
######################## OOP in Python ########################
2+
3+
class pandas: # making class
4+
owner = "RK" #Class variable
5+
6+
def __init__(self,name): #constructer
7+
self.name = name #instance variable
8+
print("{0} in pnandas".format(name))
9+
10+
def method(self): #method
11+
print('Method')
12+
13+
def update(upname):
14+
pandas.owner=upname
15+
print(pandas.owner)
16+
17+
def book(self,Name,date):
18+
self.Name = Name
19+
self.date = date
20+
21+
print(self.Name,self.date)
22+
23+
pnd = pandas("Rohan") #making object using class
24+
pnd2 = pandas("Ravindi")
25+
26+
pnd.method()
27+
28+
#update class variable
29+
pandas.update("HMRK")
30+
31+
#Addrass of the object
32+
33+
print(id(pnd))
34+
35+
#Memory size calculate by constructer
36+
37+
pnd.book("Madolduwa",90-78)
38+
pnd2.book("hinsare",56-89)
39+
40+
class Student:
41+
42+
School = "NSBM"
43+
44+
def __init__(self,m1,m2,m3):
45+
self.m1 = m1
46+
self.m2 = m2
47+
self.m3 = m3
48+
49+
def avg(self):
50+
return (self.m1+self.m2+self.m3)/3
51+
52+
def get_m1(self): #getter
53+
return self.m1
54+
55+
def set_m1(self,value): #setter
56+
self.ml = value
57+
58+
@classmethod # cls and this line use for class method
59+
def info(cls):
60+
return cls.School
61+
62+
@staticmethod
63+
def infocls():
64+
print("This is Student class")
65+
66+
67+
68+
s1 = Student(89,56,56)
69+
s2 = Student(45,89,75)
70+
71+
print(s1.avg())
72+
print(s2.avg())
73+
74+
print(Student.info())
75+
Student.infocls()
76+
77+
######### class in class ##########3
78+
79+
class Student1:
80+
def __init__(self,name,rollno):
81+
self.name = name
82+
self.rollno = rollno
83+
self.lap = self.laptop() # make class objector in construcor
84+
85+
86+
def show(self):
87+
print(self.name,self.rollno)
88+
89+
class Laptop:
90+
91+
def __init__(self):
92+
self.brand = "Asuss"
93+
self.cpu = "i7"
94+
self.ram = 8
95+
96+
t1 = Student("Rohan",98123)
97+
t2 = Student("Ravindi",98615)
98+
99+
lap1 = t1.lap
100+
lap2 = t2.lap
101+
102+
103+
104+

0 commit comments

Comments
 (0)