DEV Community

Cover image for Understanding Variables
Mary Nyandia
Mary Nyandia

Posted on

Understanding Variables

Today I explored one of the most important building blocks in Python ; variables. Variables are like containers that store information we can use later in our program. They make our code dynamic and reusable.

✨ What I Learned

1. Declaring Variables
You can assign values to variables using the = operator:

first_name = 'Asabeneh'
last_name = 'Yetayeh'
country = 'Finland'
city = 'Helsinki'
age = 250
is_married = True

Enter fullscreen mode Exit fullscreen mode

Here, I stored text (strings), numbers (integers), and even a boolean (True/False).

2. Storing Collections
Variables can also hold lists and dictionaries:

skills = ['HTML', 'CSS', 'JS', 'React', 'Python']
person_info = {
    'firstname': 'Asabeneh',
    'lastname': 'Yetayeh',
    'country': 'Finland',
    'city': 'Helsinki'
}

Enter fullscreen mode Exit fullscreen mode

This is powerful because it lets us group related information together.

3. Printing Values
Using print(), I displayed the values stored in variables

print('First name:', first_name)
print('Skills:', skills)
print('Person information:', person_info)

Enter fullscreen mode Exit fullscreen mode

4. Declaring Multiple Variables in One Line
Python makes it easy to declare several variables at once:

first_name, last_name, country, age, is_married = 'Asabeneh', 'Yetayeh', 'Helsinki', 250, True

Enter fullscreen mode Exit fullscreen mode

This is a neat shortcut when you want to initialize multiple values quickly.

🎯 My Take
Variables are the foundation of Python programming. They let us store, organize, and manipulate data in flexible ways. Whether it’s a single number or a collection of skills, variables make our programs meaningful.

Top comments (0)