0Pricing
Mojo Academy · Lektion

Daten über die Brücke übertragen

Konvertieren Sie zwischen Mojo- und Python-Werten.

Daten über die Brücke übertragen ist eine kostenlose Mojo Academy-Lektion auf CoddyKit. Dies ist Lektion 3 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.

Two Worlds of Values

Mojo has its own native types, and Python has its own. Interop means converting values as they cross between the two worlds.

Mojo to Python

When you pass a Mojo value into a Python call, Mojo automatically wraps it into a PythonObject Python can understand.

var n: Int = 42
print(np.sqrt(n))

Numbers Convert Cleanly

Simple values like Int and Float move across smoothly, becoming Python ints and floats with no extra work from you.

var x: Float64 = 3.5
var r = math.floor(x)

Strings Travel Too

A Mojo String becomes a Python str on the way in, so text-based functions just work across the bridge.

var name = String("Mojo")
print(name)

Python to Mojo

Coming back, Python results arrive as a PythonObject. You then convert it into a native Mojo type when you need one.

var obj = math.factorial(5)

Unwrap to Int

To get a real Mojo number from a result, construct the type from the object, like wrapping it in Int.

var count = Int(math.factorial(5))

Unwrap to Float

The same idea works for decimals: build a Float64 from the Python result to use it in Mojo math.

var ratio = Float64(math.pi)

Unwrap to String

Turn a Python text result into a Mojo String the same way, so you can store and process it natively.

var label = String(obj)

Indexing Python Collections

You can index a Python list or array result with brackets, getting back another PythonObject to convert.

var first = arr[0]

Convert at the Edges

A good habit: keep values as PythonObjects while talking to Python, then convert to Mojo types at the boundary you control.

Why It Matters

Knowing how data crosses the bridge keeps your types predictable, so Python results flow safely into fast Mojo code. 🌉

Quick Check

Recall how to turn a Python result into a Mojo number.

Recap

You saw Mojo values become PythonObjects going in, and learned to convert results back into Int, Float, or String. 🎯

Häufig gestellte Fragen

Ist die Lektion „Daten über die Brücke übertragen“ kostenlos?

Ja — der vollständige Text von „Daten über die Brücke übertragen“ 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 „Daten über die Brücke übertragen“?

Konvertieren Sie zwischen Mojo- und Python-Werten. 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 3 von 4.

Wie lange dauert die Lektion „Daten über die Brücke übertragen“?

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. Ein Python-Modul importieren
  2. Python-Funktionen aufrufen
  3. Daten über die Brücke übertragen
  4. Wann Sie Python-Interop verwenden
← Zurück zu Mojo Academy