Hey smart coder! ๐
Are you ready to start learning Python? Before we build games and apps, we need to learn two magical things: Variables and Data Types.
Let’s dive into this fun coding world! ๐
๐ฆ What is a Variable?
Think of a variable as a box where you can store information like numbers, names, or colors.
You can open the box anytime and use what’s inside!
๐ฏ Example:
-
age
is a box with the number12
. -
name
is a box with the word"Aarav"
.
You can print them too!
๐ง Rules for Naming Variables
Just like people, variables need good names.
Here are some rules:
-
Must start with a letter (not a number)
-
Can include letters, numbers, and underscores
-
No spaces allowed
-
Don’t use Python keywords (like
if
,for
,True
)
✅ Good Variable Names:
❌ Bad Variable Names:
๐ข What are Data Types?
Data Types tell Python what kind of data you are storing in a variable.
Let’s look at the 4 most common types:
1️⃣ int → Integer (Whole Numbers)
๐งฎ These are numbers without a decimal.
2️⃣ float → Decimal Numbers
๐งช These are numbers with decimal points.
3️⃣ str → String (Text)
๐ Anything inside quotes is a string.
4️⃣ bool → Boolean (True or False)
๐ก Used when you only want to say Yes (True) or No (False).
๐งช Try it Yourself!
๐ You’ve just used 4 different data types in one mini program!
๐ Bonus: Type Checker
Want to know the type of a variable? Use type()
like this:
Try it with float
, str
, and bool
too!
๐ง Summary
Term | What It Means | Example |
---|---|---|
Variable | A box that stores data | age = 10 |
int | Whole number | score = 100 |
float | Number with decimal | height = 5.6 |
str | Text or string (in quotes) | name = "Zoya" |
bool | True or False values | is_fun = True |
๐ฏ Final Thought
Python is super smart — but only if you tell it what to store and how to store.
With variables and data types, you're now ready to create amazing programs!
๐ ️ Start building... and keep coding! ๐ป✨
No comments:
Post a Comment