Object-Oriented Programming (OOP) is a programming paradigm that organises code around real-world entities. As the course source code describes it, a class is “un segmento de codigo que nos permite simplificar el desarrollo, reutilizar codigo” — a segment of code that lets you simplify development and reuse logic. Instead of writing separate variables and functions for every person, every product, or every calculation, you define a class once and then create as many objects (instances) of that class as you need.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/marioaje/Python/llms.txt
Use this file to discover all available pages before exploring further.
Section 1 — Class Anatomy
Every Python class is built from three essential ingredients:| Building block | Purpose |
|---|---|
| Name | How the class (and its objects) are identified in your code. Defined with the class keyword. |
__init__ | The initialiser — runs automatically when a new object is created. Sets up the object’s starting state. |
| Attributes | Variables that belong to an instance, declared as self.attribute_name inside __init__. |
| Methods | Functions defined inside the class that operate on the instance’s data. Always receive self as their first argument. |
What is
self? The word self is a reference to the current instance of the class — it is the object that is calling the method. Python passes it automatically behind the scenes whenever you call a method on an object. By convention it is always the first parameter in any method definition, though the name self is not a reserved keyword — it is simply the universally accepted convention.Section 2 — The persona Class
The main class used throughout Week 3 is persona. It demonstrates __init__, instance attributes, getter-style methods, and a setter-style method all in one file.
semana3/clases.py
__init__accepts three arguments (cedula,nombre,apellido) in addition toself, and stores them as instance attributes.versionis a fixed attribute — everypersonaobject starts with"2023".devuelvacedula(),regresameelnombre(), andregresameversion()are getter-style methods — they print the current value of an attribute.cambiocedula(self, cedula)is a setter-style method — it accepts a new value and updates the instance’scedulaattribute in place.
Section 3 — Instantiating Objects
A class is just a blueprint. To use it you must create one or more instances (objects). The source file shows the full workflow — creating objects, calling getter methods, and calling a setter method:semana3/clases.py
Create an instance
Call the class like a function, passing the arguments that Python creates a new
__init__ expects:persona object and stores it in variablea.Section 4 — The Persona Class: Getters and Setters
The Semana 2/poo.py file introduces an uppercase Persona class that formalises the getter/setter pattern with the conventional get/set naming:
Semana 2/poo.py
Getter vs Setter — at a glance
| Aspect | Getter (getNombre) | Setter (setNombre) |
|---|---|---|
| Purpose | Read the current value of an attribute | Write / update the value of an attribute |
| Parameters | Only self | self + the new value |
| Returns / side-effect | Prints (or returns) the stored value | Updates self.attribute in place |
| Typical naming | get + attribute name | set + attribute name |
| Example call | Usuario.getNombre() | Usuario.setNombre("Isaac") |
Section 5 — The calculadora Class
semana3/calculadora.py shows a class that accumulates a running total through repeated calls to suma:
semana3/calculadora.py
__int__vs__init__— the initialiser here is named__int__(a typo for__init__). Because__int__is not the constructor,self.resultadois never automatically set to0.0when a new object is created. The correct special method name is__init__.suma(self, valor1)accepts exactly one extra argument and uses+=to add it toself.resultado, accumulating a running total across multiple calls.retornarresultado(self)usesreturnto hand the total back to the caller — making the result usable elsewhere in the program.- The script at the bottom contains two bugs carried over from the source:
__int__is never invoked, andnuevavariable.suma(capturavalor1, capturavalor2)passes two arguments to a method that only accepts one, which raises aTypeErrorat runtime.