Functions are one of the most important building blocks in any programming language. In Python, a function is a named block of code that you can write once and run as many times as you need. As the course comments put it, functions help simplificar el desarrollo, reutilizar codigo — they simplify development and make your code reusable. Instead of writing the same logic in multiple places, you wrap it in a function, give it a name, and call it wherever it is needed.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 — Function with No Parameters
The simplest kind of function takes no input at all. It simply runs the same code every time it is called.funciones.py
imprimeMensaje() prints a fixed welcome message. Because it has no parameters, the parentheses in both the definition and the call are empty. This is useful when a piece of logic is always identical — no external data is required.
Section 2 — Functions with Parameters
Parameters let you pass information into a function so it can work with dynamic data rather than hard-coded values.Single parameter
funciones.py
textoMensaje is a parameter — a local variable that receives whatever value you pass when calling the function. You can pass any string, number, or object.
Multiple parameters
funciones.py
test) shows how Python separates multiple parameters with commas. Both values are available inside the function body, though in this example only textoMensaje is printed.
A practical two-parameter example
Thesuma function from Week 1 is a great real-world illustration of a function that receives two parameters and performs a computation:
Semana 1/suma.py
input() always returns a string, so the values are converted with int() before being passed to suma. This is a common pattern whenever you collect numeric input from a user.
Section 3 — Functions with a Return Value
So far every function has usedprint() to show output. But often you need a function to produce a value that your program can store and use later. That is what return is for.
funciones.py
funcionRetorno() evaluates 3 + 3 and hands the result (6) back to whoever called it. cualquiera() does the same with 6 + 6, returning 12. The calling code receives those values and can store them in variables or use them in expressions.
print() vs return — they look similar but behave very differently.print()displays a value on the screen. Once the function finishes, that value is gone; the caller receivesNone.returnhands a value back to the caller. The caller can store it, pass it to another function, or use it in a calculation.
return whenever the result of a function needs to be used elsewhere in your program. Use print() only when the sole purpose of the function is to show something to the user.Section 4 — Calling Functions
Defining a function does nothing on its own — you must call it to run its code. The source file includes commented-out examples that demonstrate the three calling styles:funciones.py
Call a no-parameter function
Simply write the function name followed by empty parentheses:Python finds the function, runs its body, and returns to the next line.
Call a function with a parameter
Pass the argument inside the parentheses — either a literal or a variable:The string
"Hola clase" is assigned to textoMensaje inside the function.No parameters
imprimeMensaje() — just call the name with empty parentheses.With parameters
imprimeMensajePersonalizado(variable) — pass data inside the parentheses.Two parameters
imprimeMensajePersonalizados(texto, test) — separate multiple arguments with commas.Return value
resultado = funcionRetorno() — capture the returned value in a variable.