0Pricing
Mojo Academy · Lektion

Funktionssignaturen lesen

Verstehen Sie eine Funktion anhand ihrer Deklaration.

Funktionssignaturen lesen ist eine kostenlose Mojo Academy-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Mojo Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Mojo Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

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.

Häufig gestellte Fragen

Ist die Lektion „Funktionssignaturen lesen“ kostenlos?

Ja — der vollständige Text von „Funktionssignaturen lesen“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Mojo Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Mojo Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Funktionssignaturen lesen“?

Verstehen Sie eine Funktion anhand ihrer Deklaration. Du übst Mojo Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Mojo Academy zu starten?

Keine Vorkenntnisse erforderlich. Mojo Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.

Wie lange dauert die Lektion „Funktionssignaturen lesen“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Mojo Academy-Lektion Code schreiben und ausführen?

Ja. Jede Mojo Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Positions- und Keyword-Argumente
  2. Standardwerte für Argumente
  3. Mehrere Werte zurückgeben
  4. Funktionssignaturen lesen
← Zurück zu Mojo Academy