Classes and objects
Python is an object-oriented language. This paradigm organizes programs around two fundamental concepts: classes and objects.
OOP (Object-Oriented Programming) is a fundamental approach in programming that is based on the creation and manipulation of objects to effectively and efficiently solve problems. This lesson provides you with the essential skills to work with object-oriented programming and address problems in a structured and modular way. Enhance your programming skills through practical exercises and master the principles of object-oriented programming.
Python is an object-oriented language. This paradigm organizes programs around two fundamental concepts: classes and objects.
The attributes are the variables that store the data of an object, and the methods are the functions that define what the object…
A constructor is the special method that runs automatically when an object is created, and it is used to give its attributes…
Many languages have keywords such as public or private to control who can use an attribute. Python has no such keywords: it…
Getters and setters are methods used to read and modify the attributes of an object in a controlled way. For example, to validate…
Inheritance lets you create a new class from one that already exists. The new class (the subclass ) receives all the attributes…
Polymorphism means "many forms": objects of different classes respond to the same message (the same method), each in its own way.
Sometimes you want a class that serves only as a template : it defines which methods its subclasses must have, but it makes no…
This article brings together three tools that complete a class: special methods (with double underscores), attributes shared by…
So far everything your objects store belongs to each object . But sometimes there is data or functions that belong to the class…
Inheritance is a powerful tool that can be misused. This article covers the advanced cases and when another option is better.
Create a Python program that asks the user for three names and stores them in a list of objects of the Person class.
Create a Python program that asks the user for three names and stores them in a list of objects of the Person class.
Develop a Python program made of three classes: Person , Student and Teacher . The Student and Teacher classes inherit from the…
Develop a Python program to manage a photo album using object-oriented programming.
Create a class called Person with the attributes name (text), age (integer) and address (text).
Develop a Python program that asks the user for three names and stores them in a list of Person objects. Two of them are students…
Create a Python program that models several geometric shapes from the following class diagram. The diagram represents public…
Develop a Python program that implements an interface called IVehicle . In Python an interface is an abstract class ( abc.ABC )…
Create a Python program with an abstract class Animal that has a name and three methods: set_name(name) , get_name() and eat() …
A class protects its data: the balance only changes through methods that check that the operation is valid and, if it is not…
Instance attributes are different in each object; class attributes are shared by all of them. A @classmethod works with the class…
With special methods ( __add__ , __sub__ , __eq__ …) your objects can use Python operators as if they were numbers.
If a class defines __iter__ , __len__ and __contains__ , its objects behave like collections: they are traversed with for …
Inheritance lets a subclass reuse a base class and specialize it, and polymorphism makes the same method behave differently…
A stack (last in, first out) is a good example of an abstract data type : the class hides how it stores the elements and offers…