Python-Funktionen aufrufen
Rufen Sie Python-Code auf und lesen Sie Ergebnisse.
Python-Funktionen aufrufen ist eine kostenlose Mojo Academy-Lektion auf CoddyKit. Dies ist Lektion 2 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.
From Import to Action
Importing a module is just step one. The real payoff is calling its functions and getting results back into your Mojo program.
Call With Dots
Use the module handle and dot syntax to call a function, exactly like in Python: module name, dot, function, parentheses.
var root = math.sqrt(16)Pass Arguments Normally
Send arguments inside the parentheses just as you would in Python. Mojo forwards them across the bridge for you.
var biggest = builtins.max(3, 9, 5)Results Are PythonObjects
A Python call returns a PythonObject, a flexible wrapper that can hold any Python value the function produced.
var result = np.add(2, 3)Print It Directly
You can print a PythonObject straight away. Mojo asks Python for its text form, so output looks just like in Python.
print(np.array([1, 2, 3]))Chain Method Calls
Because results are Python objects, you can call methods on them too, chaining calls just like fluent Python code.
var text = greeting.upper()Keyword Arguments Work
Named arguments carry over the bridge as well, so you can call Python functions with keyword arguments by name.
var a = np.zeros(5, dtype=np.int32)Calls Can Raise
A Python function might throw, so calling it can raise in Mojo. Put such calls in a function marked with raises.
fn use() raises:
var r = math.sqrt(2)Access Attributes Too
You are not limited to functions. Read module attributes and constants the same way, with simple dot access.
var tau = math.tauFull Library Power
Calling Python functions means the entire API of a library is available, letting you orchestrate rich logic from Mojo.
Why It Matters
You can drive proven Python code from Mojo, mixing convenient libraries with your own fast Mojo logic in one program. 🚀
Quick Check
Recall what a Python function call gives back in Mojo.
Recap
You called Python functions with dot syntax, passed arguments, and received a PythonObject result you can print or reuse. 🎯
Häufig gestellte Fragen
Ist die Lektion „Python-Funktionen aufrufen“ kostenlos?
Ja — der vollständige Text von „Python-Funktionen aufrufen“ 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 „Python-Funktionen aufrufen“?
Rufen Sie Python-Code auf und lesen Sie Ergebnisse. 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 2 von 4.
Wie lange dauert die Lektion „Python-Funktionen aufrufen“?
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
- Ein Python-Modul importieren
- Python-Funktionen aufrufen
- Daten über die Brücke übertragen
- Wann Sie Python-Interop verwenden