Int、Float、Bool
Mojoの数値型と真偽値型を扱います
「Int、Float、Bool」はCoddyKit上の無料Mojo Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはMojo Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Mojo Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Values Have Types
Every value belongs to a type that says what it is and what you can do with it. Three core types start you off.
Int for Whole Numbers
An Int holds whole numbers like counts and indexes, with no fractional part at all.
var count = 42Math with Int
Ints support the usual arithmetic. Add, subtract, and multiply them just as you would expect on whole numbers.
var apples = 3 + 4
print(apples)Float for Decimals
A Float stores numbers with a decimal point, perfect for measurements, prices, and anything fractional.
var price = 9.99Int and Float Differ
10 is an Int but 10.0 is a Float. The decimal point is what makes a literal a Float instead of an Int.
var whole = 10
var fraction = 10.0Float Division
Dividing with / gives a Float result so fractions are not lost. That keeps precision when numbers do not divide evenly.
var half = 5 / 2
print(half)Bool Is True or False
A Bool holds just one of two values: True or False. It answers yes-or-no questions in your logic.
var is_ready = TrueComparisons Make Bools
Comparing values produces a Bool. The expression 3 > 2 evaluates to True, while 1 == 2 is False.
var bigger = 3 > 2
print(bigger)Bools Drive Decisions
Bools feed your if-statements later. Storing a comparison in a clearly named Bool makes branching code read well.
var is_adult = age >= 18Pick the Right Number Type
Use Int when fractions cannot exist, like a head count. Reach for Float when a value can have a decimal.
Three Tools, Many Programs
Int, Float, and Bool already cover counting, measuring, and deciding. Most logic you write leans on these core types.
Quick Check
You write the literal 10.0 instead of 10 in your Mojo code. What type is that value?
Recap
Int counts, Float measures with decimals, and Bool holds True or False. Comparisons produce Bools that steer your logic. 🎯
よくある質問
「Int、Float、Bool」レッスンは無料ですか?
はい。「Int、Float、Bool」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Mojo Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Mojo Academyコースには全4レッスンが含まれています。
「Int、Float、Bool」で何を学びますか?
Mojoの数値型と真偽値型を扱います ブラウザで直接実行するハンズオンコードでMojo Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Mojo Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのMojo Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「Int、Float、Bool」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このMojo Academyレッスンでコードを書いて実行できますか?
はい。すべてのMojo Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- varによる値の宣言
- Int、Float、Bool
- 文字列とテキスト
- 役立つ型アノテーション