0Pricing
Mojo Academy · Lesson

Calling Python Functions

Invoke Python code and read results.

Calling Python Functions is a free Mojo Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Mojo Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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.tau

Full 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. 🎯

Frequently asked questions

Is the “Calling Python Functions” lesson free?

Yes — the full text of “Calling Python Functions” is free to read here on the web, and the Mojo Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Mojo Academy course, upgrade to CoddyKit PRO.

What will I learn in “Calling Python Functions”?

Invoke Python code and read results. You practise Mojo Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Mojo Academy?

No prior experience is required. Mojo Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Calling Python Functions” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Mojo Academy lesson?

Yes. Every Mojo Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Importing a Python Module
  2. Calling Python Functions
  3. Moving Data Across the Bridge
  4. When to Use Python Interop
← Back to Mojo Academy