Python Variables

Hey friends 👋 welcome back, In the last lesson, we learned how to run our first Python program, Today, we are going to learn about variables, one of the most important concepts in programming, Variables are like containers that store information for your program, You can store numbers, text, or other data in a variable and use it later.

Creating a Variable

In Python, you do not need to declare the type of a variable, You just give it a name and assign a value using =, Example:

# storing a number age = 14 # storing text name = "Yusuf" # storing a decimal number height = 1.6

Explanation

age, name, height are the variable names, = is the assignment operator, it gives the variable a value, and 14, "Yusuf", 1.6 are the values stored in the variables.

Using Variables

Once you have a variable, you can use it anywhere in your code, For example:

age = 14 name = "Yusuf" print("My name is", name) print("I am", age, "years old")

Output:

My name is Yusuf I am 14 years old

Python replaces name and age with the values stored in them.

Rules for Naming Variables

1, Can only contain letters, numbers, and underscores _, Example: first_name, age_14
2, Must start with a letter or underscore, Example: name1 ✅, 1name
3, Cannot use Python keywords like print, if, for
4, Variable names are case-sensitive, Example: Age and age are different

Changing Variable Values

You can update a variable anytime:

score = 10 print("Score:", score) score = 20 print("Updated Score:", score)

Output:

Score: 10 Updated Score: 20

Practice Time

Create a Python file called variables.py and try these exercises, 1, Store your name in a variable and print it, 2, Store your age in a variable and print it, 3, Store your height in a variable and print it, 4, Change the value of your age and print the new value

Great job, You just learned how to store and use information in Python, In the next lesson, we will learn about data types, where we will explore numbers, text, and more, We will soon be launching our YouTube channel, where we are going to post step-by-step video tutorials on Python and other tech skills, These videos will make learning easier and more visual, helping beginners follow along confidently.