0Pricing
Mojo Academy · レッスン

varによる値の宣言

Mojoで名前付き変数を作成します

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

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

Why You Need Names

A program juggles many values. To reuse one later you give it a name. In Mojo you create a named value with var. 📦

Your First var

Write var, then a name, then = and a value. Mojo stores the value under that name so you can use it again.

var score = 100

Reading the Value Back

Once declared, use the name anywhere you want that value. Here score stands in for 100 when you print it.

var score = 100
print(score)

Names Hold Things You Compute

A var does not have to be a literal. You can name the result of an expression so the math happens once.

var total = 100 + 50
print(total)

Changing a var Later

A var is mutable: assign a new value any time without repeating var. The name simply points at its latest value.

var score = 100
score = 250

Choose Clear Names

Good names describe the value. Prefer user_age over x so your code reads like plain English later.

var user_age = 30

snake_case Style

Mojo names use lowercase words joined by underscores, called snake_case. It matches Python and keeps code tidy.

var first_name = "Ada"

Declare Before You Use

You must create a name before reading it. Using a name Mojo has never seen is an error, which catches typos early.

One Name, One Value at a Time

A var holds a single value. Reassigning replaces the old one entirely, so the previous value is simply gone.

var mode = "easy"
mode = "hard"

var Inside a Function

Most vars live inside a function. They exist while the function runs and describe that function's local work.

fn main():
    var greeting = "hi"
    print(greeting)

var Makes Code Readable

Naming a value once and reusing it beats retyping the same number. A clear var is documentation that runs.

Quick Check

You want to store a number so you can reuse it later in your code. Which keyword declares it?

Recap

Use var to name a value, read it by name, and reassign it later. Clear snake_case names make your code easy to follow. 🎯

よくある質問

「varによる値の宣言」レッスンは無料ですか?

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

「varによる値の宣言」で何を学びますか?

Mojoで名前付き変数を作成します ブラウザで直接実行するハンズオンコードでMojo Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

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

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

「varによる値の宣言」レッスンにはどのくらい時間がかかりますか?

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

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

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

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

  1. varによる値の宣言
  2. Int、Float、Bool
  3. 文字列とテキスト
  4. 役立つ型アノテーション
← Mojo Academyに戻る