Dux-Courses Evaluations
COURSESDOCUMENTATION
RoadmapRanking
Tutorial Daily ChallengePLAYGROUNDARENA
LoginSign Up
Aurum-Courses

Aurum Courses is an advanced learning and evaluation platform designed to accelerate your tech career. We provide an immersive environment filled with challenges, technical documentation, and verifyable certificates for frontend, backend, and fullstack technologies.

Platform Links

  • Interactive Courses
  • Technical Documentation
  • My Profile & Progress
Aurum-Courses
  • Privacy Policy
  • Terms of Service
  • Cookies Management

Our Network

  • Aurumdux
  • MiniDuxTools
© 2026 Aurum-Courses. All rights reserved. Made with passion for the developer ecosystem.

Developed by Aurumdux

Docs/Python/Clases y POO
Intermediopython

Clases y POO

Aprende a modelar entidades con clases, herencia y metodos especiales en Python.

Definir una clase

Las clases actuan como plantillas para crear objetos. El metodo __init__ es el constructor.
python
1class Producto:
2    def __init__(self, nombre: str, precio: float, stock: int = 0):
3        self.nombre = nombre
4        self.precio = precio
5        self.stock = stock
6
7    def aplicar_descuento(self, porcentaje: float):
8        self.precio *= (1 - porcentaje / 100)
9
10    def __str__(self):
11        return f"{self.nombre} - ${self.precio:.2f} ({self.stock} uds)"
12
13laptop = Producto("MacBook Pro", 2499.99, 15)
14laptop.aplicar_descuento(10)
15print(laptop)

Herencia

La herencia permite crear clases nuevas basadas en existentes, reutilizando su codigo.
python
1class Vehiculo:
2    def __init__(self, marca, modelo, anio):
3        self.marca = marca
4        self.modelo = modelo
5        self.anio = anio
6
7    def info(self):
8        return f"{self.marca} {self.modelo} ({self.anio})"
9
10class Auto(Vehiculo):
11    def __init__(self, marca, modelo, anio, puertas=4):
12        super().__init__(marca, modelo, anio)
13        self.puertas = puertas
14
15    def info(self):
16        return f"{super().info()} - {self.puertas} puertas"
17
18mi_auto = Auto("Toyota", "Corolla", 2024)
19print(mi_auto.info())
← AnteriorFunciones y DecoradoresSiguiente →Manejo de Errores y Excepciones