0Pricing
Mojo Academy · Aula

Lendo assinaturas de funções

Entenda uma função a partir da sua declaração.

Lendo assinaturas de funções é uma aula grátis de Mojo Academy no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Mojo Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Mojo Academy inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em 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.

Perguntas Frequentes

A aula “Lendo assinaturas de funções” é grátis?

Sim — o texto completo de “Lendo assinaturas de funções” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Mojo Academy, atualize para CoddyKit PRO. O curso de Mojo Academy inclui 4 aulas no total.

O que vou aprender em “Lendo assinaturas de funções”?

Entenda uma função a partir da sua declaração. Você pratica Mojo Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Mojo Academy?

Nenhuma experiência prévia é necessária. Mojo Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “Lendo assinaturas de funções”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Mojo Academy?

Sim. Cada aula de Mojo Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Argumentos posicionais e nomeados
  2. Valores padrão de argumentos
  3. Retornando vários valores
  4. Lendo assinaturas de funções
← Voltar para Mojo Academy