-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp16.py
1446 lines (757 loc) · 41.3 KB
/
p16.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
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Object Oriented Programming
# common topic in almost all popular programming languages (PYTHON, C++, JAVA) with common idea but with different syntax
# oop is just a style/way to write a code
# very helpful in creating real world programs
# we will see other advantages when we will start learning loop
# class, object(instance), method
# list class
# list object
# method
l=[1,2,3]
l2=[4,5,6]
l3=['Ravin',' Rakholiya']
l.append(8)
# create your first class
# OBJECTIVES
# WHAT IS CLASS
# WHAT IS INIT METHOD --or-- constructor
# WHAT ARE INIT METHOD, INSTANCE VARIABLES
# HOW TO CREATE OUR OBJECT
class Person:
def __init__(self, first_name, last_name, age): # it is called as init method or constructor
# instance variable # self represents object like p1 and p2
self.first_name=first_name # whenever we call init method, self should be first argument. and self represents our object.
self.last_name=last_name
self.age=age
p1=Person("Ravinkumar","Rakholiya",22)
p2=Person("Rupenkumar","Rakholiya1",19)
print(p1.first_name) # o/p: Ravinkumar
print(p2.first_name) # o/p: Rupenkumar
class Person11:
def __init__(self, first_name, last_name, age):
# instance variables
print("init method // constructor get called")
self.first_name=first_name
self.last_name=last_name
self.age=age
p1=Person11("Ravinkumar","Rakholiya",22) # o/p: init method // constructor get called
p1=Person11("Ravinkumar","Rakholiya",22) # init method called when we create object.
p2=Person11("Rupenkumar","Rakholiya1",19)
# o/p: init method // constructor get called
# init method // constructor get called
# class Person111:
# def __init__(person_obj, first_name, last_name, age):
# # instance variables
# person_obj.person_first_name=first_name # person_first_name----> instance variable
# person_obj.last_name=last_name
# person_obj.age=age
# p1=Person111("Ravinkumar","Rakholiya",22)
# print(p1.person_first_name) # o/p: Ravinkumar
# Excercise 1
# create class laptop with attributes like brand name, model name, price
# create two objects/instance of your laptop class
class Laptop:
def __init__(self, brand_name, model_name, price):
# instance variable
self.brand_name=brand_name
self.name=model_name
self.price=price # we can create more instance variable
self.laptop1=brand_name+" "+model_name
lp1=Laptop("Dell","inspire 5558",52500)
lp2=Laptop("HP","micro 1355",48000)
print(lp1.name) # o/p: inspire 5558
print(lp1.laptop1) # o/p: Dell inspire 5558
# in python, the all functions which are inside the class called as function.
# Instance method
l1=[1,2,3] # here, l1 is instance of List class, means l1 is object of our List class
class Person1:
def __init__(self,first_name,last_name,age):
self.first_name=first_name
self.last_name=last_name
self.age=age
def full_name(self):
return f"{self.first_name} {self.last_name}"
def is_above_18(self):
return True if self.age>18 else False
# or return self.age>18
p1=Person1("Ravin","Rakholiya",22)
p2=Person1("Rupen","Rakholiya",17)
print(p1.full_name()) # o/p: Ravin Rakholiya
print(p2.full_name()) # o/p: Rupen Rakholiya
print(Person1.full_name(p2)) # o/p: Rupen Rakholiya
# p2.full_name()=Person1.full_name(p2)
print(p1.is_above_18()) # o/p: True
print(Person1.is_above_18(p1)) # o/p: True
print(p2.is_above_18()) # o/p: False
print(Person1.is_above_18(p2)) # o/p: False
l4=[1,2,3]
l5=[1,2,3]
# clear, pop
l4.clear()
print(l4) # o/p: []
list.clear(l5)
print(l5) # o/p: []
# append
l4.append(10)
print(l4) # o/p: [10]
list.append(l4,20)
print(l4) # o/p: [10, 20]
# Excercise 2
class Laptop1:
def __init__(self, brand_name, model_name, price):
# instance variable
self.brand_name=brand_name
self.name=model_name
self.price=price
def laptop_discount(self,disc):
a=(self.price*disc)/100
return self.price-a
lp1=Laptop1("Dell","inspire 5558",52500)
n=int(input("Enter percentage for discount\n"))
print(lp1.laptop_discount(n))
# Class Variable
# class---->circle
# method---> area, circum
class Circle:
def __init__(self, radius, pi):
self.radius=radius
self.pi=pi
def circum_cir(self):
return 2*self.pi*self.radius
def area_cir(self):
return self.pi*(self.radius**2)
c=Circle(4,3.14)
c1=Circle(6,3.14)
print(c.circum_cir()) # o/p: 25.12
print(c1.area_cir()) # o/p: 113.04
# here are two problems
# 1). we write pi value 3.14 when we create object, like in above case we made two object, hence we have to write 3.14 two times.....2). as a result 3.14 store in memory for each objects, so it will take more space, which is reason of memory wastage.
class Circle1:
pi = 3.14 # class variable
def __init__(self, radius):
self.radius=radius
def circum_cir(self):
return 2*Circle1.pi*self.radius # we can use class variable like class_name.class_variable_name
def area_cir(self):
return Circle1.pi*(self.radius**2)
c2=Circle1(4)
c3=Circle1(6)
print(c2.circum_cir()) # o/p: 25.12
print(c3.area_cir()) # o/p: 113.04
class Laptop2:
lap_disc=10
def __init__(self, brand_name, model_name, price):
# instance variable
self.brand_name=brand_name
self.name=model_name
self.price=price
def laptop_discount(self):
a=(self.price*Laptop2.lap_disc)/100
return self.price-a
lp3=Laptop2("Dell","inspire 5558",52500)
lp4=Laptop2("Hp","inspire 5558",50000)
print(lp3.laptop_discount()) # o/p: 47250.0
print(lp4.laptop_discount()) # o/p: 45000.0
class Laptop3:
lap_disc1=10
def __init__(self, brand_name, model_name, price):
# instance variable
self.brand_name=brand_name
self.name=model_name
self.price=price
def laptop_discount(self):
a=(self.price*Laptop3.lap_disc1)/100
return self.price-a
Laptop3.lap_disc1=0
lp5=Laptop3("Dell","inspire 5558",52500)
lp6=Laptop3("Hp","inspire 5558",50000)
print(lp5.laptop_discount()) # o/p: 52500.0
print(lp6.laptop_discount()) # o/p: 50000.0
# how can we see, object has which variables
print(lp5.__dict__) # o/p: {'brand_name': 'Dell', 'name': 'inspire 5558', 'price': 52500}
print(lp6.__dict__) # o/p: {'brand_name': 'Hp', 'name': 'inspire 5558', 'price': 50000}
# here, if we want to apply discount 30 for only Hp's laptop so....
lp6.lap_disc1=30
print(lp6.laptop_discount()) # o/p: 45000.0 the output took disc=10 , so we can not get right answer using this method
class Laptop4:
lap_disc2=10
def __init__(self, brand_name, model_name, price):
# instance variable
self.brand_name=brand_name
self.name=model_name
self.price=price
def laptop_discount(self):
a=(self.price*self.lap_disc2)/100
return self.price-a
lp7=Laptop4("Dell","inspire 5558",52500)
lp8=Laptop4("Hp","inspire 5558",50000)
lp8.lap_disc2=30
print(lp8.laptop_discount()) # o/p: 35000.0 this is right answer dic=30 for hp
print(lp7.laptop_discount()) # o/p: 47250.0 this is right answer dic=10 for dell
# Excercise 3
class Person2:
count_instance=0
def __init__(self, first_name,last_name):
self.first_name=first_name
self.last_name=last_name
# self.count_instance+=1 # here we will get 0 as out put because we have to take class variables by class name
Person2.count_instance+=1
p21=Person2("Ravin","Rakholiya")
p22=Person2("Ravin1","Rakholiya1")
print(Person2.count_instance) # o/p: 2
# class Methods
# difference between class method and instance method
# class variable = class attribute
class Person3:
count_instance=0 # class variable --or-- class attribute ------> same for all objects of the class, we can call class variable by using class name with . operator
def __init__(self, first_name, last_name, age): # instance method
Person3.count_instance+=1
self.first_name=first_name
self.last_name=last_name
self.age=age
@classmethod # declaration of class method
def instance_count(cls):
return f"you have created {cls.count_instance} instances in {cls.__name__} class" # here we can write Person3.count_instance and Person3.__name__ insted of cls.count_instance and cls.__name__
def full_name(self): # instance method
return f"{self.first_name} {self.last_name}"
def is_above_18(self): # insatnce method -------i can use instance method with instance(p31,p32) of the class
return self.age>18
p31=Person3("Ravin","Rakholiya",10)
p32=Person3("Rupen","Rakholiya1",19)
print(Person3.instance_count()) # calling class method # o/p: you have created 2 instances in Person3 class # this thing, we can access by using instance name.
print(p31.instance_count()) # o/p: you have created 2 instances in Person3 class # but we should not do this
# in instance method first argument is object(self), while in class method the first argument is class(cls)
# class methods as a constructors
# when we create our instance(object), its call init method which is counstructor
# but here, we want to create object in different way, which calls class method and would be constructor for that instance
class Person4:
count_instance=0
def __init__(self, first_name, last_name, age):
Person4.count_instance+=1
self.first_name=first_name
self.last_name=last_name
self.age=age
@classmethod
def instance_count(cls):
return f"you have created {cls.count_instance} instances in {cls.__name__} class"
@classmethod
def from_string(cls,string):
first,last,age=string.split(',')
return cls(first,last,int(age))
def full_name(self):
return f"{self.first_name} {self.last_name}"
def is_above_18(self):
return self.age>18
p41=Person4("Ravin","Rakholiya",10)
p42=Person4("Rupen","Rakholiya1",19)
p43=Person4.from_string('Yash,Rakholiya2,20')
print(p43.full_name()) # o/p: Yash Rakholiya2
print(p43.is_above_18()) # o/p: True
# Static Method
# class method is related with our class
# instance method is related with our instance
# but static method is not related with our class and instance
# static method is like our normal function
# static method has logical relation with our class
# we can create static method by using static method decorator
class Person5:
count_instance=0
def __init__(self, first_name, last_name, age):
Person3.count_instance+=1
self.first_name=first_name
self.last_name=last_name
self.age=age
@classmethod
def instance_count(cls):
return f"you have created {cls.count_instance} instances in {cls.__name__} class"
@classmethod
def from_string(cls,string): # cls represents our class
first,last,age=string.split(',')
return cls(first,last,int(age))
@staticmethod # creating static method
def hello():
print('hello, static method called')
def full_name(self): # self represents out instance
return f"{self.first_name} {self.last_name}"
def is_above_18(self):
return self.age>18
p51=Person5("Ravin","Rakholiya",10)
p52=Person5("Rupen","Rakholiya1",19)
Person5.hello() # calling static method # o/p: hello, static method called
# Encapsulation ----encapulate data in class (encaptulate methods data in a class)
# It describes the idea of wrapping data and the methods that work on data within one unit.
# A class is an example of encapsulation as it encapsulates all the data that is member functions, variables, etc.
# Consider a real-life example of encapsulation, in a company, there are different sections like the accounts section, finance section, sales section etc. The finance section handles all the financial transactions and keeps records of all the data related to finance. Similarly, the sales section handles all the sales-related activities and keeps records of all the sales. Now there may arise a situation when for some reason an official from the finance section needs all the data about sales in a particular month. In this case, he is not allowed to directly access the data of the sales section. He will first have to contact some other officer in the sales section and then request him to give the particular data. This is what encapsulation is. Here the data of the sales section and the employees that can manipulate them are wrapped under a single name “sales section”. As using encapsulation also hides the data. In this example, the data of any of the sections like sales, finance or accounts are hidden from any other section.
# Abstraction ----hide the complexity (method hide main logic)
# Abstraction means hiding the complexity and only showing the essential features of the object. So in a way, Abstraction means hiding the real implementation and we, as a user, knowing only how to use it.
# Real world example would be a vehicle which we drive with out caring or knowing what all is going underneath.
# or A TV set where we enjoy programs with out knowing the inner details of how TV works.
# Abstraction in Python is achieved by using abstract classes and interfaces.
# Some special Naming Conventions ----show as private for developer, but not private
# Name Mangling ---- __name (not a convention)
class Phone:
def __init__(self, brand, model_name, price):
self.brand=brand
self.model_name=model_name
# self._price=price
self.__price=price
def make_a_call(self, phone_number):
print(f"calling {phone_number}.......")
def full_name(self):
return f"{self.brand} {self.model_name}"
def send_message(self):
pass #twilio
l=[4,2,7,1,5]
l.sort() # python use tim sort for sorting, hide complexity
print(l) # o/p: [1, 2, 4, 5, 7]
# with out encapsulation, abstraction is not possible.
# convention
# in python, everything is public.
# '_' (underscore) is convention------> we use this because, i can say to other developer that don't make changes in it and treat as private method because it is private. but you know it is not private, anyone can make changes in it
# _name ---> convention of private name
# __name__ ----> it is called as double underscore method, or dunder, or magic method
phone1=Phone('nokia','1100',1000)
# print(phone1._price) # o/p: 1000
# phone1._price=-1000
# print(phone1._price) # o/p: -1000
# Name mangling ----> _classname__attributename
# print(phone1.__price) # o/p: AttributeError: 'Phone' object has no attribute '__price'
print(phone1.__dict__) # o/p: {'brand': 'nokia', 'model_name': '1100', '_Phone__price': 1000} # here, python changed __price as _Phone__price
print(phone1._Phone__price) # o/p: 1000
phone1._Phone__price=-1000
print(phone1._Phone__price) # o/p: -1000
print(phone1.brand) # o/p: nokia
# Property, Setter decorator
# will discuss three prblems in existing
# then we will solve them using getter, setter decorator
class Phone1:
def __init__(self, brand, model_name, price):
self.brand=brand
self.model_name=model_name
self._price=price
self.complete_specification=f"{self.brand} {self.model_name} and price is {self._price}"
def make_a_call(self, phone_number):
print(f"calling {phone_number}.......")
def full_name(self):
return f"{self.brand} {self.model_name}"
phone11=Phone1('nokia','1100',1000) # problem 1) here i can enter negative price, which is practically not possible in life, because phone has not negative price
print(phone11.brand) # o/p: nokia
print(phone11.model_name) # o/p: 1100
print(phone11._price) # o/p: 1000
print(phone11.complete_specification) # o/p: nokia 1100 and price is 1000
print(phone11.brand) # o/p: nokia
print(phone11.model_name) # o/p: 1100
phone11._price=500 # problem 3) here we can also set negative price which is not possible for phone in real life
print(phone11._price) # o/p: 500 # problem 2) price of the phone is updated here but not updated in below line(complete_specification)
print(phone11.complete_specification) # o/p: nokia 1100 and price is 1000
# how can we solve this problems
# we can set price 0 when user add negative price
phone11=Phone1('nokia','1100',1000)
class Phone2:
def __init__(self, brand, model_name, price):
self.brand=brand
self.model_name=model_name
# if price>0:
# self._price=price
# else: # solution 1
# self._price= 0 ----OR----
self._price=max(price,0)
# self.complete_specification=f"{self.brand} {self.model_name} and price is {self._price}" # solution 2-----> this should not be written here, and make function which return this
@property # if i use property decorator here, i don't need to call it as a function
def complete_specification(self): # soln 2
return f"{self.brand} {self.model_name} and price is {self._price}"
# getter(), setter() # solution 3
@property # it will return price
def price1(self): # getter method
return self._price
@price1.setter
def price1(self,new_price): # setter method
self._price=max(new_price,0)
def make_a_call(self, phone_number):
print(f"calling {phone_number}.......")
def full_name(self):
return f"{self.brand} {self.model_name}"
#soln 1
phone21=Phone2('nokia','1100',1000)
phone22=Phone2('nokia','1100',-1000)
print(phone21._price) # o/p: 1000
print(phone22._price) # o/p: 0
# soln 2
phone21._price=500
print(phone21._price) # o/p: 500
# print(phone21.complete_specification()) # o/p: nokia 1100 and price is 500 # soln 2 (without property decorator)
print(phone21.complete_specification) # o/p: nokia 1100 and price is 500 # soln 2 (with property decorator)
# soln 3
phone21._price=-500
print(phone21._price) # o/p: -500
print(phone21.complete_specification) # o/p: nokia 1100 and price is -500
phone21.price1=-500
print(phone21.price1) # o/p: 0
print(phone21.complete_specification) # o/p: nokia 1100 and price is 0
# Inheritance
class Phone3: # base clss/Parent class
def __init__(self, brand, model_name, price):
self.brand=brand
self.model_name=model_name
self._price=max(price,0)
def make_a_call(self, phone_number):
print(f"calling {phone_number}.......")
def full_name(self):
return f"{self.brand} {self.model_name}"
class Smartphone(Phone3): # derived clss/child class
def __init__(self, brand, model_name, price, ram, internal_memory, rear_camera):
#two ways to get parant class varibles
# Phone3.__init__(self, brand, model_name, price) # 1) uncommon way
super().__init__(brand, model_name, price) # 2) common way ----> here we don't need to pass self as argument in super
self.ram=ram
self.internal_memory=internal_memory
self.rear_camera=rear_camera
phone31=Phone3('nokia','1100',1000)
smartphone=Smartphone("Redmi","Y2",9000,"3 GB","32 GB","16 mpx")
print(phone31.full_name()) # o/p: nokia 1100
print(smartphone.full_name()) # o/p: Redmi Y2
print(smartphone.full_name()+f" and price is : {smartphone._price}") # o/p: Redmi Y2 and price is : 9000
# Can we derive more than one class from base class
# Multilevel inheritane
# Method resolution order (MRO)
# Method Overriding
# isinstance(), issubclass()
# Can we derive more than one class from base class ----> YES
class Phone4: # parent class / base class
def __init__(self, brand, model_name, price):
self.brand=brand
self.model_name=model_name
self._price=max(price,0)
def full_name(self):
return f"{self.brand} {self.model_name}"
def make_a_call(self,number):
return f"calling {number}......"
class Smartphone1(Phone4): # child class / derived class
def __init__(self, brand, model_name, price, ram, internal_memory, rear_camera):
super().__init__(brand, model_name, price)
self.ram=ram
self.internal_memory=internal_memory
self.rear_camera=rear_camera
class Smartphone2(Phone4): # child class / derived class
def __init__(self, brand, model_name, price, ram, internal_memory, rear_camera):
super().__init__(brand, model_name, price)
self.ram=ram
self.internal_memory=internal_memory
self.rear_camera=rear_camera
smartphone1=Smartphone2("Samsung","s10",50000,"8 GB","64 GB","32 mpx")
print(smartphone1.full_name()) # o/p: Samsung s10
# Multilevel inheritane
class Phone5: # parent class / base class
def __init__(self, brand, model_name, price):
self.brand=brand
self.model_name=model_name
self._price=max(price,0)
def full_name(self):
return f"{self.brand} {self.model_name}"
def make_a_call(self,number):
return f"calling {number}......"
class Smartphone3(Phone5): # child class / derived class
def __init__(self, brand, model_name, price, ram, internal_memory, rear_camera):
super().__init__(brand, model_name, price)
self.ram=ram
self.internal_memory=internal_memory
self.rear_camera=rear_camera
def my_storage(self):
return f"Ram is : {self.ram} and Internal storage is : {self.internal_memory}"
class FlagshipPhone(Smartphone3):
def __init__(self, brand, model_name, price, ram, internal_memory, rear_camera, front_camera):
super().__init__(brand, model_name, price, ram, internal_memory, rear_camera)
self.front_camera=front_camera
p=FlagshipPhone("One+","o1",65000,"12 GB","128 GB","64 mpx","32 mpx")
print(p.full_name()) # o/p: One+ o1
print(p.my_storage()) # o/p: Ram is : 12 GB and Internal storage is : 128 GB
# MRO (Method resolution Order)
# every class has method resolution order
# How we can see (print) method resolution order
# print(help(Smartphone3))
# o/p: Help on class Smartphone3 in module __main__:
# class Smartphone3(Phone5)
# | Smartphone3(brand, model_name, price, ram, internal_memory, rear_camera)
# |
# | Method resolution order:
# | Smartphone3 .# this is order of python is searching for
# | Phone5 # firstly, python checks in SmartPhone3, then in Phone5 and then object
# | builtins.object # this is master class in python, all classes are inherited from it in Python
# |
# | Methods defined here:
# |
# | __init__(self, brand, model_name, price, ram, internal_memory, rear_camera)
# | Initialize self. See help(type(self)) for accurate signature.
# |
# | my_storage(self)
# |
# | ----------------------------------------------------------------------
# | Methods inherited from Phone5:
# |
# | full_name(self)
# |
# | make_a_call(self, number)
# |
# | ----------------------------------------------------------------------
# | Data descriptors inherited from Phone5:
# |
# | __dict__
# | dictionary for instance variables (if defined)
# |
# | __weakref__
# | list of weak references to the object (if defined)
# print(help(FlagshipPhone))
# o/p: Help on class FlagshipPhone in module __main__:
# class FlagshipPhone(Smartphone3)
# | FlagshipPhone(brand, model_name, price, ram, internal_memory, rear_camera, front_camera)
# |
# | Method resolution order:
# | FlagshipPhone
# | Smartphone3
# | Phone5
# | builtins.object
# |
# | Methods defined here:
# |
# | __init__(self, brand, model_name, price, ram, internal_memory, rear_camera, front_camera)
# | Initialize self. See help(type(self)) for accurate signature.
# |
# | ----------------------------------------------------------------------
# | Methods inherited from Smartphone3:
# |
# | my_storage(self)
# |
# | ----------------------------------------------------------------------
# | Methods inherited from Phone5:
# |
# | full_name(self)
# |
# | make_a_call(self, number)
# |
# | ----------------------------------------------------------------------
# | Data descriptors inherited from Phone5:
# |
# | __dict__
# | dictionary for instance variables (if defined)
# |
# | __weakref__
# | list of weak references to the object (if defined)
# Method Overriding -----> m ethod has same name in different classes with different arguments