Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Inheritance | Inheritance
Object-Oriented Programming in Python

bookInheritance

Inheritance's main idea is to use already defined classes and produce new ones by improving and extending some other classes.

Some class Animal contains all common attributes and methods for all animals. The Cat class inherits the Animal class.

123456789
class Animal: pass # Inheriting the Animal class class Cat(Animal): pass print(Animal) print(Cat)
copy

Note

  • The common class (that is inherited by other classes) is called a superclass or parent class;
  • The class that inherits is called a child class;
  • The child class has all the same methods and attributes that parents have and can have additional ones, but not vice versa;
  • Each class in Python can have multiple parent classes and/or children's classes;
  • Each class in Python is a children's class of Object class.

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 1

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Suggested prompts:

Pregunte me preguntas sobre este tema

Resumir este capítulo

Mostrar ejemplos del mundo real

Awesome!

Completion rate improved to 7.69

bookInheritance

Desliza para mostrar el menú

Inheritance's main idea is to use already defined classes and produce new ones by improving and extending some other classes.

Some class Animal contains all common attributes and methods for all animals. The Cat class inherits the Animal class.

123456789
class Animal: pass # Inheriting the Animal class class Cat(Animal): pass print(Animal) print(Cat)
copy

Note

  • The common class (that is inherited by other classes) is called a superclass or parent class;
  • The class that inherits is called a child class;
  • The child class has all the same methods and attributes that parents have and can have additional ones, but not vice versa;
  • Each class in Python can have multiple parent classes and/or children's classes;
  • Each class in Python is a children's class of Object class.

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 1
some-alt