Tutorial
Variables in Python
A variable is like a box with a label. You can put a value inside the box and later find it by its name. Variables let you store information in your program.
Why Use Variables?
Variables make coding easier. Instead of typing the same number or text multiple times, you store it once and reuse it anywhere in your code.
How to Create a Variable
To create a variable, write a name, then =, and then the value you want to store:
Now age stores 15, and name stores "Sam". You can use these variables anywhere in your code.
Printing Variable Values
You can print a variable's value to see what it holds:
Changing Variable Values
You can change the value of a variable anytime:
Quick Recap
- Variables store data that you can reuse.
- Create variables using
=. - Print variables to see their values.
- Variables can hold different values, and you can change them anytime.
Using variables makes your code flexible and easy to read. Next, you’ll learn about the types of data variables can hold.