0Pricing
Mojo Academy · Lección

Leer firmas de funciones

Entienda una función a partir de su declaración.

Leer firmas de funciones es una lección gratuita de Mojo Academy en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Mojo Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Mojo Academy incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

The Signature Is the Contract

A function's signature is its first line: the name, the parameters, and the return type. Read it well and you know how to call the function.

fn area(width: Int, height: Int) -> Int:

Spotting the Name

Right after fn or def comes the name. It should hint at what the function does, like area, parse, or connect.

fn parse(text: String) -> Int:

Reading the Parameters

Inside the parentheses are the parameters the function expects. Each pairs a name with a type, telling you what to pass in.

fn area(width: Int, height: Int) -> Int:

Parameter Types Guide You

The type after each colon tells you the kind of value to send. width: Int means area expects a whole number, not text.

fn greet(name: String, times: Int): ...

The Return Type Arrow

The arrow points to what the function gives back. Here -> Int promises an integer result you can store or print.

fn area(width: Int, height: Int) -> Int:

No Arrow Means No Value

When there is no arrow, the function returns None. It does its work for the side effect, like printing, not for a result.

fn log(msg: String):
    print(msg)

Defaults in the Signature

An equals sign in a parameter marks a default. It signals the value is optional and shows the fallback Mojo will use.

fn open(path: String, mode: String = "r"): ...

raises Warns of Failure

A raises keyword on the signature means the function can fail. That tells you to wrap your call in error handling.

fn read(path: String) raises -> String:

fn vs def at a Glance

The opening word matters. fn means strict and typed; def means flexible and Python-like. The signature tells you which contract you are under.

def loose(x): ...
fn strict(x: Int) -> Int: ...

A Signature as Mini-Docs

Before reading any body, the signature already answers what goes in and what comes out. Treat it as the function's summary.

Putting It All Together

Name, parameters, defaults, return type, and raises: each part of the signature is a clue. Together they tell you exactly how to use the function.

fn fetch(url: String, retries: Int = 3) raises -> String:

Quick Check

In a Mojo signature, what does the part after the arrow tell you?

Recap: Read Before You Call

A signature shows the name, parameters with types, any defaults, the return type, and raises. Read it first and calling correctly becomes easy.

Preguntas frecuentes

¿La lección «Leer firmas de funciones» es gratis?

Sí — el texto completo de «Leer firmas de funciones» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Mojo Academy, actualiza a CoddyKit PRO. El curso de Mojo Academy incluye 4 lecciones en total.

¿Qué aprenderé en «Leer firmas de funciones»?

Entienda una función a partir de su declaración. Practicas Mojo Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Mojo Academy?

No se requiere experiencia previa. Mojo Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.

¿Cuánto tiempo toma la lección «Leer firmas de funciones»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Mojo Academy?

Sí. Cada lección de Mojo Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Argumentos posicionales y de palabra clave
  2. Valores de argumentos predeterminados
  3. Devolver varios valores
  4. Leer firmas de funciones
← Volver a Mojo Academy