-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoopsbackup.py
More file actions
268 lines (192 loc) · 5.68 KB
/
Copy pathoopsbackup.py
File metadata and controls
268 lines (192 loc) · 5.68 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# # class Factory:
# # def __init__(self): #Constructor function is called
# # print(self)#whenever a new object is created
# # print("how are you")##and this self will target the location of objects
# # print("this is p23 batch")
# # a = Factory()
# # b= Factory()
# # c = Factory()
# # ## 2nd use of constructor function
# # class Factory:
# # def __init__(self,zips,pockets,material):
# # self.zips = zips
# # self.pockets = pockets
# # self.material = material
# # def details(self):
# # print("Your Bag detail are ::---")
# # print(self.zips)
# # print(self.pockets)
# # print(self.material)
# # reebok = Factory(2,3,"Leather")
# # campus = Factory(4,2,"plastic")
# # reebok.details()
# # print(campus.material)
# class Registration:
# age = 18 #class attributes
# name = "sarthak"
# email = "dk@gmail.com"
# def __init__(self,name,email,age,number):
# if Registration.age >= age:
# self.name = name #object attribute
# self.email = email
# self.number = number
# else:
# print("you cannot register you are underage")
# return
# def details(self): #object method ---it target the location of object
# print(self.name)#self will take the location of object
# print(self.email)#whichever object is calling
# print(self.number)
# print(self.number)
# print(self.age)
# print(self.age)
# @classmethod
# def dummy_details(cls):
# print(cls.name)#class method - it will always access
# print(cls.email)
# print(cls.number)
# print(cls.age)
# print(cls.age)
# @staticmethod #static method
# def college_details(): # this method will not target any location
# print("I am very bad collegeI will take your money "\
# "and I will not teach you anything"\
# "welcome to real world")
# Student1 = Registration("harsh","harsh@gmail.com",21,1234567890)
# Student1.dummy_details()
# Student1
# ### Inherutance
# ## one class attributes and methods can be accessed by another class this thing is known as inheritance
# class BhopalFactory:
# Reg_number = 1683732396772
# def __init__(self,color,size,type):
# self.color = color
# self.size = size
# self.type = type
# def details(self):
# print(self.color)
# print(self.size)
# print(self.type)
# class indorefactory(BhopalFactory):
# def __init__(self,color,size,type,price):
# super().__init__(color,size,type)
# self.price = price
# class UjjainFactory(indorefactory):
# def __init__(self, color, size, type, price):
# super().__init__(color, size, type, price)
# shoe1 = BhopalFactory("Red",7,"jordan")
# shoe2 = indorefactory("yellow",9,"sneakers",1000)
# shoe2.details()
##multilevel
#########
class Animal:
def __init__(self,name):
self.name = name
class Human:
def __init__(self,name,age):
self.name = name
self.age = age
def speak(self):
print("hello human you speak")
class robot(Animal,Human):
def __init__(self, name,age):
Human.__init__(self,name,age)
obj = robot("alpha1",21)
obj.speak()
##hybrid inheritance
class Animal:
pass
class Human:
pass
class Robots(Animal,Human):
pass
class AI(Robots):
pass
###polymorphism
class Animal:
name = "lion"
def __init__(self,name,age):
self.name = name
self.age = age
def detail(self):
print("the details are :--")
class Human:
name = "Harsh"
def __init__(self,name,age,gender):
self.name = name
self.age = age
self.gender = gender
obj1 = Animal("giraffe",6)
obj2 = Human("harsh",23,"male")
obj1.detail()
obj2.detail()
##here both
###
class BhopalFactory:
Reg_number = 1683732396772
def __init__(self,color,size,type):
self.color = color
self.size = size
self.type = type
def details(self):
print(self.color)
print(self.size)
print(self.type)
class indorefactory(BhopalFactory):
def __init__(self,color,size,type,price):
super().__init__(color,size,type)
self.price = price
def details(self):
print(super().details())
print(self.price)
obj = indorefactory("red",8,"jordan",180000)
obj.details()
##this obj can now only call one method that is of indorefactory
#it cannot call bhopalfactory detail method
#this thing is known as method overriding
##method overloading
class Animal:
def hello(a):
pass
def hello(a,b):
pass
obj = Animal()
obj.hello(12,45)
## same name methods inside a single class but with different parameters this thing is known as method overriding
# it is not available in python
##Encapsulation
class Animal:
a = 12 #public attribute
_b = 23 #protected attribute
__c = 45 # private attribute
def hello(self):
print("how are you")
def _hello2(self):#protected method
print("how are you2")
def __hello3(self):#private method
print("how are you 2")
@classmethod
def __hello3(self): #private method
print("how are you 3")
obj = Animal()
print(obj.a)
##Abstraction
from abc import ABC , abstractmethod
class person(ABC):
@abstractmethod
def info():
pass
@abstractmethod
def register():
pass
class Teacher(person):
def info():
pass
def register():
pass
class Student(person):
def info():
pass
def register():
pass
obj = Teacher()