Data Types πΊπ°π‘οΈπ‘
Different data needs different containers. String (text), Integer (whole numbers), Float (decimals), Boolean (True/False). Choose the right type or code breaks.
Day 3: Data Types β The Right Box for the Right Thing
Why Do Types Matter?
You can't put water in a paper bag. You can't put coins in a bottle. Same with code β text goes in strings, numbers go in integers. Use the wrong container and your code breaks!
The Four Types
String β text, always in quotes.
username = "priya"
city = "Hyderabad"
Integer β whole numbers, no quotes.
age = 21
likes = 500
Float β decimal numbers, no quotes.
rating = 4.8
price = 99.99
Boolean β only True or False, capital letters.
is_online = True
is_banned = False
Real World Connection
Zomato stores your name as String, your order total as Float, delivery time as Integer, and whether you're a premium user as Boolean. Every app uses all four types constantly!
The Big Rule
Is it text? String with quotes. Is it a whole number? Integer. Is it a decimal? Float. Is it yes or no? Boolean. Follow this and you'll never get confused!
Common Mistakes
Storing a number as text β then you can't do math with it!
age = "21" # WRONG β this is text, not a number!
age = 21 # CORRECT β now you can do age + 1
Mini Challenge
Mini Challenge
Create one variable of each type β name, age, rating, and is_student. Print them all. Then try adding 1 to age. Does it work? Now try adding 1 to name. What happens?
Quick Quiz
Q: Which type stores "Hyderabad"? A: String β it's text, use quotes!
Q: Zomato rating is 4.5 β which type? A: Float β it has a decimal!
Q: is_logged_in β which type and what values can it have? A: Boolean β only True or False!
Key Takeaways
Key Takeaways
- String = text in quotes. Integer = whole number. Float = decimal. Boolean = True/False.
- Wrong type = broken code. Always pick the right container!
- Numbers without quotes can do math. Numbers with quotes are just text.
- Boolean is always capital T or F β True or False.
Continue Learning with Rohi
You've used your 3 free Rohi questions. Create a free account to continue learning.