-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsuper.py
More file actions
34 lines (19 loc) · 776 Bytes
/
super.py
File metadata and controls
34 lines (19 loc) · 776 Bytes
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
#Accessing parent method into a child class with super()
class Racer:
def __init__(self, name):
self.name = name
def getName(self):
return self.name
def getSkill(self):
return 'normal'
class ItalianRider(Racer):
def __init__(self, name): #to make automatic, we create function __init__
# Racer.__init__(self, name) #to call __init__ Racer from parent then it run well
super().__init__(name) #if the Class name somehow too long, we can use super() to access parent's method
print('Hello argentina')
def getSkill(self):
return 'smoother'
Rider = ItalianRider('Rossi')
print(Rider.getName() + " is " + Rider.getSkill())
# Description
"""when we use super(), we don't need to use the self parameter"""