What are Python Variables?
Categories: Python
A variable is a container for a value. It can be assigned a name, you can use it to refer to it later in the program.
Based on the value assigned, the interpreter decides its data type. You can always store a different type in a variable.
For example, if you store 7 in a variable, later, you can store ‘Dinosaur’.
1. Python Variables Naming Rules
There are certain rules to what you can name a variable(called an identifier).
Python variables can only begin with a letter(A-Z/a-z) or an underscore(_).
>>> 9lives=9
2. Assigning and Reassigning Python Variables
To assign a value to Python variables, you don’t need to declare its type.
You name it according to the rules stated in section 2a, and type the value after the equal sign(=).
>>> age=10
>>> print(age)
Output
10
3. Multiple Assignment
You can assign values to multiple Python variables in one statement.
>>> age,city=21,'Indore'
>>> print(age,city)
Output
21 Indore