Int, Float, and Bool
Work with Mojo's numeric and boolean types.
Int, Float, and Bool 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.
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. 🎯
Frequently asked questions
Is the “Int, Float, and Bool” lesson free?
Yes — the full text of “Int, Float, and Bool” 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 “Int, Float, and Bool”?
Work with Mojo's numeric and boolean types. 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 “Int, Float, and Bool” 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
- Declaring Values with var
- Int, Float, and Bool
- Strings and Text
- Type Annotations That Help