Variables

christian.dinh2481 total contributions
Published May 6, 2021Updated Sep 9, 2021
Contribute to Docs
A variable is used to store data that will be used by the program. This data can be a number, a string, a Boolean, a list or some other data type. Every variable has a name which can consist of letters, numbers, and the underscore character _
.
The equal sign =
is used to assign a value to a variable. After the initial assignment is made, the value of a variable can be updated to new values as needed.
Variable Names
A variable can have a short name (like x
and y
) or a more descriptive name (age
, grade
, grocery_list
).
Rules for Python variables:
- A variable name must start with a letter or the underscore character. It cannot start with a number.
- A variable name can only contain alpha-numeric characters and underscores (
A
-z
,0
-9
, and_
). - Variable names are case-sensitive (
num
,Num
, andNUM
are three different variables).
Examples
These are all valid variable names and assignment:
user_name = "@sonny420"user_id = 100verified = False
A variable’s value can be changed after assignment
All contributors
- christian.dinh2481 total contributions
- Anonymous contributorAnonymous contributor3077 total contributions
- christian.dinh
- Anonymous contributor
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.