Skip to content

Commit 9b9a589

Browse files
author
Karandeep Grover
committed
formatted
1 parent f5a1166 commit 9b9a589

File tree

3 files changed

+34
-23
lines changed

3 files changed

+34
-23
lines changed
Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
class Animal:
2-
def __init__(self, living_place):
3-
self.living_place = living_place
2+
def __init__(self, habitat):
3+
self.habitat = habitat
4+
5+
def print_habitat(self):
6+
print(self.habitat)
7+
8+
def sound(self):
9+
print("Some Animal Sound")
410

5-
def printplace(self):
6-
print(self.living_place)
711

812
class Dog(Animal):
9-
def __init__(self, living_place):
10-
super().__init__(living_place)
13+
def __init__(self):
14+
super().__init__("Kennel")
15+
16+
def sound(self):
17+
print("Woof woof!")
1118

12-
x = Dog("zoo")
13-
x.printplace()
1419

20+
x = Dog()
21+
x.print_habitat()
22+
x.sound()

Basics/Hindi/17_inheritance/inheritance.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
## Exercise: Inheritance
22

3-
1. create inheritance using animal dog relation.
3+
1. create inheritance using animal Dog relation.
44

55

66
```
77
for example,
8-
animal and dog both has same living_place so create a method for living_place
8+
Animal and Dog both has same habitat so create a method for habitat
99
```
1010

1111
2. use super() constructor for calling parent constructor.
1212

1313
```
14-
class animal:
14+
class Animal:
1515
#code
1616
17-
class dog(animal):
18-
super()-it refers animal class,now you can call animal's methods.
17+
class Dog(Animal):
18+
super()-it refers Animal class,now you can call Animal's methods.
1919
```
2020

2121
[Solution](https://github.com/codebasics/py/blob/master/Basics/python_basics/17_inheritance/17_inheritance.py)
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
class Teacher():
2-
def teachers_action(self):
3-
print('I can teach')
1+
class Teacher:
2+
def teachers_action(self):
3+
print("I can teach")
44

55

6-
class Engineer():
6+
class Engineer:
77
def Engineers_action(self):
8-
print('I can code')
8+
print("I can code")
99

10-
class Youtuber():
10+
11+
class Youtuber:
1112
def youtubers_action(self):
12-
print('I can code and teach')
13+
print("I can code and teach")
14+
15+
16+
class Person(Teacher, Engineer, Youtuber):
17+
pass
1318

1419

15-
class Person(Teacher, Engineer, Youtuber):
16-
pass
17-
coder = Person()
20+
coder = Person()
1821
coder.teachers_action()
1922
coder.Engineers_action()
2023
coder.youtubers_action()

0 commit comments

Comments
 (0)