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
The use of modules and packages in Python is an essential practice that enhances code organization and reuse. A module is a .py
file that contains definitions and declarations of functions, variables and classes that you can reuse in different parts of a project and even in multiple projects. By dividing code into modules, you improve not only the organization, but also the maintainability of a project. This "divide and conquer" method results in a more efficient and easier to manage code.
To really understand modules, it is useful to see them in action. Let's say you have a project that needs to generate sales and expense reports. You can split this functionality into two parts within a module called reports.py
.
# reports.pydef generate_sales_report(month, sales): return f "Report for {month}month : Total sales =${sales}"
def generate_expense_report(month, expenses): return f "Report for {month}month : Total expenses =${expenses}"
Once the functions are defined, you can consume them from another file in your project by simply importing them.
# application.pyimport reports
sales_report = reports.generate_sales_report("October", 10000)expense_report = reports.generate_expense_report("October", 5000)
print(sales_report)print(expense_report)
This structure allows you to reuse the functions of the reports
module without rewriting them, guaranteeing efficiency in your projects.
Sometimes, you may only need one or two functions from a module. In these cases, it is convenient to use the from import
statement to bring only those parts needed, optimizing the performance of the program.
# application_dos.pyfrom reports import generate_sales_report
sales_report_nov = generate_sales_report("november", 12000)print(sales_report_nov)
If you need to import more functions, simply add them in a comma separated list:
from reports import generate_sales_report, generate_expense_report
sales_report_nov = generate_sales_report("November", 12000)expense_report_nov = generate_expense_report("November", 6000)
print(sales_report_nov)print(expense_report_nov)print(expense_report_nov).
This method not only improves the clarity of the code, but also keeps the size of your application small, since only what you will actually use matters.
The use of modules in Python has several crucial advantages:
We encourage you to implement this practice! Try to create a module that manages the finances of a company, calculating month by month the balance sheet and determining the profitability. This activity will consolidate your knowledge of modules and their application, taking you further on your programming learning journey.
Continue to explore this fascinating world; every line of code you write is a step forward in your development as a programmer!
Contributions 27
Questions 0
Want to see more contributions, questions and answers from the community?