DEV Community

SAINAPEI LENAPUNYA
SAINAPEI LENAPUNYA

Posted on

Day 2: Storing Information with Variables - 30 Days of Python Challenge

Welcome Back!

Hey everyone! It's Day 2 of my 30 Days of Python Challenge, and I'm so excited you're back! Yesterday we learned about the print() function, and today we're leveling up by learning how to store and reuse information with variables.

If you missed Day 1, check it out [here] to catch up on print statements!

Day 2: Variables - Your Data Containers

Today's mission: Understanding Variables. Think of variables as labeled boxes where you can store different types of information. Instead of typing the same information over and over, we store it once and use it everywhere!

What I Learned

Variables are like name tags for your data. They let you:

  • Store information to use later
  • Make your code more flexible and reusable
  • Give meaningful names to your data

In Python, creating a variable is super simple: just pick a name, use the equals sign (=), and assign a value!

My Code

Here's what I wrote for Day 2:

# Day 2 - Variables
name = "Sanaipei"
print("My name is", name)

age = 23
print("I am", age, "years old")

height_m = 5.213
print("My height is", height_m, "meters")

is_student = False
print("Am I a student?", is_student)
Enter fullscreen mode Exit fullscreen mode

Breaking It Down ๐Ÿ”

Let me walk you through each part:

  1. name = "Sanaipei" - This creates a variable called name and stores the text "Sanaipei" in it. This is a string (text data).

  2. print("My name is", name) - Notice how I can use the variable name instead of typing "Sanaipei" again? The print() function automatically adds spaces between items separated by commas.

  3. age = 23 - Here I'm storing a number without quotes. This is an integer (whole number).

  4. height_m = 5.213 - This stores a decimal number, called a float in Python. Perfect for measurements!

  5. is_student = False - This is a boolean value. Booleans can only be True or False (notice the capital letters!). They're great for yes/no situations.

Output

When you run this code, you'll see:

My name is Sanaipei
I am 23 years old
My height is 5.213 meters
Am I a student? False
Enter fullscreen mode Exit fullscreen mode

Different Data Types at a Glance

Today I worked with four different data types:

  • String ("Sanaipei") - Text wrapped in quotes
  • Integer (23) - Whole numbers
  • Float (5.213) - Decimal numbers
  • Boolean (False) - True or False values

Python is smart enough to figure out what type of data you're storing based on how you write it!

Key Takeaways ๐Ÿ’ก

  • Variables store data so you can reuse it throughout your code
  • Use descriptive names for your variables (like age instead of a)
  • Python has different data types: strings, integers, floats, and booleans
  • You can print multiple items in one print() statement by separating them with commas
  • Variable names should be lowercase with underscores for spaces (height_m, not heightM)

What's Next?

Tomorrow on Day 3, I'll be exploring type casting - how to convert one data type to another. What if I want to turn the number 23 into the text "23"? Stay tuned!

Let's Connect! ๐Ÿ’ฌ

I'd love to hear from you!

  • Have you created your first variables yet?
  • What creative variable names have you come up with?
  • Any questions about data types?

Drop a comment below! If you're coding along, share what you stored in your variables I'd love to see your creative examples!

Don't forget to follow me for daily updates on this journey. Day 3 tomorrow! ๐Ÿ’ช

Happy Coding!

Top comments (1)

Collapse
 
hammglad profile image
Hamm Gladius

Thanks for sharing this post and taking the time to write it!