0Pricing
Mojo Academy · レッスン

Pythonオブジェクトを読み戻す

Pythonから返された結果を展開します

「Pythonオブジェクトを読み戻す」はCoddyKit上の無料Mojo Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはMojo Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Mojo Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Results Come Back

When a Python function returns, you get a value back in Mojo. Knowing how to unpack it lets you use the result in your code. 📦

Always a PythonObject

Every Python call returns a PythonObject, Mojo's wrapper around whatever Python produced, be it a number, string, or array.

var total = np.sum(a)

Convert to Int

To use a result as a native Mojo number, convert it. Wrapping it with Int turns a Python integer into a Mojo Int.

var count = Int(py_len)

Convert to Float

For decimal results, use Float64 to pull a Python float into a Mojo floating-point value you can compute with.

var mean = Float64(py_mean)

Read Attributes

You can keep using dot access on a returned object to read its attributes, exactly as you would in Python itself.

var size = arr.size

Index Into Results

If the result is a sequence, index it with brackets. Each element is itself a PythonObject you can convert next.

var first = a[0]

Call Methods Back

Returned objects keep their Python methods. Call them with dot syntax to transform results further before reading them.

var flat = arr.flatten()

Convert to Mojo String

To turn a Python text result into native Mojo text, wrap it with String so you can store and join it normally.

var label = String(py_text)

Convert Early

Once you need real Mojo computation, convert the result out of PythonObject. Staying wrapped keeps you slow inside the Python world.

Check for Truth

Python results can be tested in conditions too. Convert with Bool when you need a yes-or-no answer from a returned object.

if Bool(py_flag):
    print("ready")

Why It Matters

Reading results back lets you blend Python output with fast Mojo logic, getting answers out of libraries and into your kernels. ⚡

Quick Check

Recall how you turn a Python integer result into a usable Mojo number.

Recap

You learned every Python call returns a PythonObject, and how to convert it with Int, Float64, or String to use the result in Mojo. 🎯

よくある質問

「Pythonオブジェクトを読み戻す」レッスンは無料ですか?

はい。「Pythonオブジェクトを読み戻す」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Mojo Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Mojo Academyコースには全4レッスンが含まれています。

「Pythonオブジェクトを読み戻す」で何を学びますか?

Pythonから返された結果を展開します ブラウザで直接実行するハンズオンコードでMojo Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Mojo Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのMojo Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。

「Pythonオブジェクトを読み戻す」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このMojo Academyレッスンでコードを書いて実行できますか?

はい。すべてのMojo Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. MojoからNumPyを使う
  2. MojoのデータをPythonに渡す
  3. Pythonオブジェクトを読み戻す
  4. 相互運用におけるパフォーマンスの注意点
← Mojo Academyに戻る