Fundamentos de Programación y Python
¿Por qué aprender Python?
Introducción a Python
Conceptos Básicos de Programación
Práctica: Te doy la bienvenida a los ejercicios interactivos
Manipulación de Cadenas de Texto en Python
Enteros, Flotantes y Booleanos
Todo lo que Debes Saber sobre print en Python
Operaciones Matemáticas en Python
Operaciones de Entrada/Salida en Consola
Colección y Procesamiento de Datos en Python
Listas
Método slice
Listas de más dimensiones y Tuplas
Aplicación de Matrices
Diccionarios
Comprehension Lists en Python (CLASE NUEVA)
Control de Flujo en Python
Estructuras condicionales
Bucles y Control de Iteraciones
Generadores e Iteradores
Funciones y Manejo de Excepciones en Python
Uso de Funciones en Python
Funciones Lambda y Programación Funcional en Python
¿Cómo realizar una función recursiva en Python?
Manejo de Excepciones y Uso de Pass (CLASE NUEVA)
Programación Orientada a Objetos en Python
Fundamentos de Programación Orientada a Objetos en Python
Ejercicio Biblioteca con POO
Herencia en POO con Python
Objetos heredados
Los 4 pilares de la programacion orientada a objetos
Uso de super() en Python (CLASE NUEVA)
Superando los Fundamentos de Programación Orientada a Objetos en Python
Lectura y escritura de archivos
Manejo de Archivos .TXT (CLASE NUEVA)
Manejo de Archivos CSV (CLASE NUEVA)
Manejo de Archivos JSON (CLASE NUEVA)
Biblioteca estándar de Python
Biblioteca estándar en Python (CLASE NUEVA)
Librería Os, Math y Random (CLASE NUEVA)
Librería Statistics y Análisis Estadístico (CLASE NUEVA)
Proyecto final: Guerra naval
Conceptos avanzados de Python
Recapitulación de lo aprendido hasta ahora
Escribir código Pythonico y profesional
Comentarios y Docstrings en Python
Scope y closures: variables locales y globales
Anotaciones de tipo
Validación de tipos en métodos
Librería Collections y Enumeraciones
Decoradores
Decoradores en Python
Decoradores anidados y con parámetros
Uso de Decoradores en clases y métodos
Métodos y estructura de clases en Python
Métodos mágicos
Sobrecarga de operadores
Implementación de `if __name__ == "__main__":`
Metaprogramación en Python
Uso de *args y **kwargs
Métodos privados y protegidos
Gestión avanzada de propiedades
Métodos estáticos y de clase avanzados
Programación concurrente y asíncrona
Introducción a la concurrencia y paralelismo
Threading y multiprocessing en Python
Asincronismo con asyncio
Asincronismo y concurrencia
Creación de módulos y paquetes
Creación de módulos en Python
Gestión de paquetes
Publicación de paquetes en PyPI
Proyecto final
Implementación de un sistema completo
Implementación de un Sistema Completo
You don't have access to this class
Keep learning! Join and start boosting your career
Object-oriented programming allows us to model real-world situations through classes and objects. In this exercise, we will learn how to create a basic structure of classes that represent different types of vehicles, including cars, bicycles and trucks. In addition, we will add additional classes to simulate a dealership and its customers, taking advantage of inheritance to encourage reuse and simplicity in the code.
We start with the creation of a Vehicle
class that will serve as a superclass for our other classes. This class defines the fundamental parameters that all vehicles share in common.
class Vehicle: def __init__(self, brand, model, price): self.brand = brand self.model = model self.price = price self.available = True
def start(self): pass # Specific implementation in child classes
def stop(self): pass # Specific implementation in child classes
Our Vehicle
class can be expanded by inheritance. Next, we create the classes Bicycle
and Truck
that inherit from Vehicle
, adapting the functions of the superclass to their specific use.
class Bicycle(Vehicle): def start(self): print(f "The bicycle {self.brand} is running")
def stop(self): print(f "The bicycle {self.brand} has stopped")
class Truck(Vehicle): def start(self): print(f "The truck {self.brand}engine is running")
def stop(self): print(f "The truck {self.brand}engine has stopped")
The Buyer
and Dealership
classes will allow interaction between vehicles and customers within the context of a store.
Buyer
class implementationThis class does not inherit from any other class, but integrates the functionality to buy and consult available vehicles.
class Buyer: def __init__(self, name): self.name = name self.collection_vehicles = []
def buy_vehicle(self, vehicle): if vehicle.available: self.collection_vehicles.append(vehicle) vehicle.available = False print(f"{vehicle.make} has been added to {self.name}' s collection ") else: print(f "Sorry, the {vehicle.make} is unavailable")
Dealer
class developmentThe Dealership
will manage the vehicle inventory and customer registration, allowing the addition and display of inventory.
class Dealership: def __init__(self): self.inventory = []self.customers = []
def add_vehicle(self, vehicle): self.inventory.append(vehicle) print(f"{vehicle.make} has been added to inventory")
def register_customer(self, customer): self.customers.append(customer) print(f"{customer.name} has been registered as a customer")
def show_vehicles_available(self): print("Vehicles available in the store:") for vehicle in self.inventory: if vehicle.available: print(f "Brand: {vehicle.brand}, Price: {vehicle.price}")
This basic system reflects how the object-oriented paradigm can be applied to represent complex situations and relationships efficiently. With this knowledge of classes and inheritance, you are equipped to create more detailed and realistic systems. Keep exploring and developing your programming skills!
Contributions 49
Questions 4
Want to see more contributions, questions and answers from the community?