#56 Python Tutorial for Beginners | Constructor in Inheritance

#56 Python Tutorial for Beginners | Constructor in Inheritance

Introduction to Inheritance in Python

In this video, Ivan introduces the concept of inheritance in Python. He explains how a subclass can inherit features from a superclass and how multiple inheritance works.

What is Inheritance?

  • A subclass can inherit features from a superclass.
  • Multiple inheritance allows one class to extend from two or more classes.

Constructor in Inheritance

  • When creating an object of a subclass, it will call the constructor of its superclass.
  • If the subclass has its own constructor, it will override the constructor of its superclass.
  • To call both constructors, use the super() method.

Method Resolution Order (MRO)

  • MRO determines the order in which methods are searched for and executed in a class hierarchy.
  • The super() method uses MRO to find and execute methods in parent classes.

Conclusion

Inheritance is an important concept in object-oriented programming that allows subclasses to reuse code from their superclasses. Understanding how constructors work and using the super() method correctly can help you write more efficient and maintainable code.

Python Super() Method Understanding Inheritance and the Super() Method

In this video, we learn about how constructors behave in inheritance, how to use the super() method, and the concept of method resolution order (MRO).

Constructors in Inheritance

  • When a subclass is created, it inherits all attributes and methods from its superclass.
  • The constructor of a subclass can be used to add new attributes or override existing ones.
  • When creating an object of a subclass, both the constructor of the subclass and its superclass are executed.

Using the Super() Method

  • The super() method allows us to call methods from a superclass.
  • We can use super() to call the constructor or other methods from a superclass.
  • When using multiple inheritance, super() follows a specific order called method resolution order (MRO).
  • MRO determines which class's method will be called first when there are multiple classes with the same method name.

Method Resolution Order (MRO)

  • MRO is determined by following a left-to-right ordering of parent classes.
  • If there are two classes with the same method name, MRO will choose the leftmost class first.
  • We can use super() to call methods from any class in our inheritance hierarchy.

Conclusion

  • In summary, we learned about constructors in inheritance, how to use the super() method for calling methods from parent classes, and MRO for determining which class's method will be called first.
  • The super() method can also be used for calling other methods besides constructors.

Turn any video into a summary like this

YouTube links, meetings, lectures. With transcripts, search, and chat.

Video description

Python Tutorial to learn Python programming with examples Complete Python Tutorial for Beginners Playlist : https://www.youtube.com/watch?v=hEgO047GxaQ&t=0s&index=2&list=PLsyeobzWxl7poL9JTVyndKe62ieoN-MZ3 Python Tutorial in Hindi : https://www.youtube.com/watch?v=JNbup20svwU&list=PLk_Jw3TebqxD7JYo0vnnFvVCEv5hON_ew Github :- https://github.com/navinreddy20/Python- Check out our courses: AI Powered DevOps with AWS - Live Course :- https://go.telusko.com/AIDevOps-AWS Coupon: TELUSKO10 (10% Discount) Complete Java Developer Course Batch-4: https://go.telusko.com/Complete4 Coupon: TELUSKO10 (10% Discount) Master Java Spring Development : https://go.telusko.com/masterjava Coupon: TELUSKO20 (20% Discount) Udemy Courses: Spring: https://go.telusko.com/udemyteluskospring Java:- https://go.telusko.com/udemyteluskojava Java Spring:- https://go.telusko.com/Udemyjavaspring Java For Programmers:- https://go.telusko.com/javaProgrammers Python : https://go.telusko.com/udemyteluskopython Git : https://go.telusko.com/udemyteluskogit Docker : https://go.telusko.com/udemyteluskodocker For More Queries WhatsApp or Call on : +919008963671 website : https://courses.telusko.com/ Editing Monitors : https://amzn.to/2RfKWgL https://amzn.to/2Q665JW https://amzn.to/2OUP21a. Follow Navin Reddy on Instagram: https://www.instagram.com/navinreddy20 Subscribe to our other channel: Navin Reddy : https://www.youtube.com/channel/UCxmk... Telusko Hindi : https://www.youtube.com/channel/UCitz... Donation: PayPal Id : navinreddy20 Patreon : navinreddy20 http://www.telusko.com/contactus

#56 Python Tutorial for Beginners | Constructor in Inheritance | YouTube Video Summary | Video Highlight