Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Constructor | Classes and Objects
Object-Oriented Programming in Python
course content

Contenido del Curso

Object-Oriented Programming in Python

Object-Oriented Programming in Python

1. Classes and Objects
2. Encapsulation
3. Inheritance
4. Polymorphism

Constructor

Constructor is a unique method that is automatically called during object creation. This method is not obligatory to define. The object can be created with the constructor generated automatically, as we did before.

Constructor syntax

Constructor has reserved name __init__().

Code

After the object is created, it contains name and hair_color attributes, that are created during the constructor call. If we don't input any values of name or hair_color, these attributes automatically have default values: 'Kitty', 'black'.

Test the code below!

¿Todo estuvo claro?

Sección 1. Capítulo 5
We're sorry to hear that something went wrong. What happened?
some-alt