python_core
python_core
Conditional
Iterative statements Transfer statements
statements
break
if
for continue
if-elif
while pass
If-elif-else
return
Different types of Inheritance
Example:
Parent
class Parent:
def method1(self):
print("parent method")
Child
class Child(Parent):
def method2(self):
print("child method")
c = Child()
c.method1() # Parent class will be available in child class also
c.method2()
Different types of Inheritance
Example:
class Parent:
def method1(self):
Multi Level Inheritance print("parent method")
class ChildChild(Child):
Child def method3(self):
print(“child child method")
Child c = ChildChild()
Child c.method1() # Grand Parent class will be available in child class also
c.method2() #Parent class
c.method3()
Different types of Inheritance
Deriving multiple child classes from
Parent class
Hierarchical Inheritance
class Parent:
def method1(self):
Parent print("parent method")
class Child1(Parent):
Child 2 def method2(self):
Child1 Child 3
print("child1 method")
class Child2(Parent):
The methods present in the def method3(self):
parent class is accessible from any print(“child2 method")
of the child class object but one
child class object cannot access c1 = Child1()
other child class method c2 = Child2()
c1.method1() # Parent class will be available in child
class also
c1.method2()
c2.method1() #parent class method
c2.method3()
Different types of Inheritance
Child is derived from 2 parent classes
Multiple Inheritance
class Parent1:
def method1(self):
print("parent 1 method")
c = Child()
c.method1() # parent1 method can be accessed
c.method2() # parent2 method can be access
c.method3() # child class method
Different types of Inheritance
Hybrid Inheritance is a combination of Single, Multi Level, Multiple and Hierarchical
inheritance
A B
G
F
Method Resolution OrderMRO(C) = C + Merge(MRO(A),
MRO(B), AB)
= C +Merge(A, Object, B,
Object, AB)
= C + A + Merge(Object, B,
Object, B)
= C + A + B + Merge(Object,
Object)
=C+A+B
Method Resolution Order
2nd example:
MRO(A) = A, object
MRO(B)= B, object
MRO(C) = C, A, object
MRO(D) = D, A, B, object
MRO(E) = E, B, object
MRO(F) = F + Merge(MRO(C), MRO(D), MRO(E),CDE)
= F+Merge(C, A, object,D, A, B, object,E, B, object, CDE)
= F+C + Merge(A, D, A, B, ,E, B, DE)
= F+C + A + Merge(D,B,E, B, DE)
= F+C+A+D+Merge(B,E,B,E)
F+C+A+D+B+Merge(E,E)
F+C+A+D+B+E
Method Resolution Order
F
Method Resolution Order