Int, Float และ Bool
ทำงานกับชนิดตัวเลขและบูลีนของ Mojo
Int, Float และ Bool เป็นบทเรียน Mojo Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน 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” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Mojo Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Mojo Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “Int, Float และ Bool”
ทำงานกับชนิดตัวเลขและบูลีนของ Mojo คุณปฏิบัติ Mojo Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Mojo Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Mojo Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน
บทเรียน “Int, Float และ Bool” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Mojo Academy นี้ได้ไหม
ได้ บทเรียน Mojo Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การประกาศค่าด้วย var
- Int, Float และ Bool
- สตริงและข้อความ
- คำอธิบายชนิดข้อมูลที่ช่วยคุณได้