filmov
tv
#3 Inheritance in python || Types of Inheritance ||Python OOP||pythonforbeginners

Показать описание
#inheritance in python#python inheritance#multiple inheritance in python#python#single inheritance in python#inheritance#what is inheritance in python#hybrid inheritance in python#multilevel inheritance in python#hierarchical inheritance in python#inheritance python#python multiple inheritance#python inheritance syntax#python inheritance program#python tutorial#single inheritance in python example#multiple inheritance#types inheritance in python#inheritance in python#python in telugu#inheritance in python in telugu#python inheritance in telugu#multiple inheritance in python#learn python in telugu#python language in telugu#python tutorial in telugu#python inheritance#inheritance in telugu#multilevel inheritance in python#python complete tutorial in telugu#python inheritance in oops#python course in telugu#python tutorials in telugu#python#single inheritance in python#inheritance
------------------------------------------------
0:00 - introduction
1:25 - types of inheritance
1:38 - single inheritance
4:20 - multi level inheritance
6:45 - multiple inheritance
7:54 - Hierarchal inheritance
8:51 - Hybrid inheritance
========================================================
==========================================
Inheritance is a fundamental concept in object-oriented programming (OOP) that allows a class (known as a child or derived class) to inherit attributes and methods from another class (known as a parent or base class). This promotes code reusability and enables the creation of hierarchical relationships between classes.
Types of inheritance in Python include:
1. **Single Inheritance**: A child class inherits from only one parent class.
2. **Multiple Inheritance**: A child class inherits from multiple parent classes.
3. **Multilevel Inheritance**: A child class inherits from a parent class, and another class inherits from this child class.
4. **Hierarchical Inheritance**: Multiple child classes inherit from a single parent class.
5. **Hybrid Inheritance**: It's a combination of two or more types of inheritance.
Each type of inheritance offers different ways to organize and structure code, depending on the relationships between classes and the requirements of the software being developed.
### 1. Single Inheritance
```python
class Animal:
def speak(self):
print("Animal speaks")
class Dog(Animal):
def bark(self):
print("Dog barks")
# Creating an instance of the child class
dog = Dog()
```
### 2. Multiple Inheritance
```python
class Bird:
def fly(self):
print("Bird flies")
class Dog:
def bark(self):
print("Dog barks")
class DogBird(Bird, Dog):
pass
# Creating an instance of the child class
dog_bird = DogBird()
```
### 3. Multilevel Inheritance
```python
class Animal:
def speak(self):
print("Animal speaks")
class Dog(Animal):
def bark(self):
print("Dog barks")
class Labrador(Dog):
def color(self):
print("Labrador is brown")
# Creating an instance of the child class
labrador = Labrador()
```
### 4. Hierarchical Inheritance
```python
class Animal:
def speak(self):
print("Animal speaks")
class Dog(Animal):
def bark(self):
print("Dog barks")
class Cat(Animal):
def meow(self):
print("Cat meows")
# Creating instances of the child classes
dog = Dog()
cat = Cat()
```
### 5. Hybrid Inheritance
```python
class A:
def method_a(self):
print("Method A")
class B:
def method_b(self):
print("Method B")
class C(A, B):
def method_c(self):
print("Method C")
class D(B, A):
def method_d(self):
print("Method D")
# Creating instances of the child classes
c = C()
d = D()
```
These examples demonstrate different types of inheritance in Python and how they can be used to model relationships between classes in various scenarios.
------------------------------------------------
0:00 - introduction
1:25 - types of inheritance
1:38 - single inheritance
4:20 - multi level inheritance
6:45 - multiple inheritance
7:54 - Hierarchal inheritance
8:51 - Hybrid inheritance
========================================================
==========================================
Inheritance is a fundamental concept in object-oriented programming (OOP) that allows a class (known as a child or derived class) to inherit attributes and methods from another class (known as a parent or base class). This promotes code reusability and enables the creation of hierarchical relationships between classes.
Types of inheritance in Python include:
1. **Single Inheritance**: A child class inherits from only one parent class.
2. **Multiple Inheritance**: A child class inherits from multiple parent classes.
3. **Multilevel Inheritance**: A child class inherits from a parent class, and another class inherits from this child class.
4. **Hierarchical Inheritance**: Multiple child classes inherit from a single parent class.
5. **Hybrid Inheritance**: It's a combination of two or more types of inheritance.
Each type of inheritance offers different ways to organize and structure code, depending on the relationships between classes and the requirements of the software being developed.
### 1. Single Inheritance
```python
class Animal:
def speak(self):
print("Animal speaks")
class Dog(Animal):
def bark(self):
print("Dog barks")
# Creating an instance of the child class
dog = Dog()
```
### 2. Multiple Inheritance
```python
class Bird:
def fly(self):
print("Bird flies")
class Dog:
def bark(self):
print("Dog barks")
class DogBird(Bird, Dog):
pass
# Creating an instance of the child class
dog_bird = DogBird()
```
### 3. Multilevel Inheritance
```python
class Animal:
def speak(self):
print("Animal speaks")
class Dog(Animal):
def bark(self):
print("Dog barks")
class Labrador(Dog):
def color(self):
print("Labrador is brown")
# Creating an instance of the child class
labrador = Labrador()
```
### 4. Hierarchical Inheritance
```python
class Animal:
def speak(self):
print("Animal speaks")
class Dog(Animal):
def bark(self):
print("Dog barks")
class Cat(Animal):
def meow(self):
print("Cat meows")
# Creating instances of the child classes
dog = Dog()
cat = Cat()
```
### 5. Hybrid Inheritance
```python
class A:
def method_a(self):
print("Method A")
class B:
def method_b(self):
print("Method B")
class C(A, B):
def method_c(self):
print("Method C")
class D(B, A):
def method_d(self):
print("Method D")
# Creating instances of the child classes
c = C()
d = D()
```
These examples demonstrate different types of inheritance in Python and how they can be used to model relationships between classes in various scenarios.