Skip to content

Commit 10a5e0e

Browse files
MRO and super
1 parent 7b8f8c3 commit 10a5e0e

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

lectures-code/mro-super-1.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright (C) Deepali Srivastava - All Rights Reserved
2+
# This code is part of Python course available on CourseGalaxy.com
3+
4+
class Person:
5+
def greet(self):
6+
print('I am a Person')
7+
8+
class Teacher(Person):
9+
def greet(self):
10+
Person.greet(self)
11+
print('I am a Teacher')
12+
13+
class Student(Person):
14+
def greet(self):
15+
Person.greet(self)
16+
print('I am a Student')
17+
18+
class TeachingAssistant(Student, Teacher):
19+
def greet(self):
20+
Student.greet(self)
21+
Teacher.greet(self)
22+
print('I am a Teaching Assistant')
23+
24+
x = TeachingAssistant()
25+
x.greet()
26+

lectures-code/mro-super-2.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (C) Deepali Srivastava - All Rights Reserved
2+
# This code is part of Python course available on CourseGalaxy.com
3+
4+
class Person:
5+
def greet(self):
6+
print('I am a Person')
7+
8+
class Teacher(Person):
9+
def greet(self):
10+
super().greet()
11+
print('I am a Teacher')
12+
13+
class Student(Person):
14+
def greet(self):
15+
super().greet()
16+
print('I am a Student')
17+
18+
class TeachingAssistant(Student, Teacher):
19+
def greet(self):
20+
super().greet()
21+
print('I am a Teaching Assistant')
22+
23+
x = TeachingAssistant()
24+
x.greet()
25+
26+
help(TeachingAssistant)
27+
s = Student()
28+
s.greet()
29+
30+

0 commit comments

Comments
 (0)