What is Variable?
Variable is a name given to the memory location which is used to store the value.
Python interpreter allocates memory according to the data type of the variable and decides what can be stored in the reserved memory. Therefore, by assigning different data types to Python variables, we can store integers, decimals or characters in the variables.
Creating Python Variables
num = 100 # Creates an integer variable
radius=10.25 # Creates a floating point variable
name="Compuhelp" # Creates a string variable
Printing Python Variables
num = 100 # Creates an integer variable
radius=10.25 # Creates a floating point variable
name="Compuhelp" # Creates a string variable
print(num)
print(radius)
print(name)
Rules to Declare Python Variables
- Variable name should be descriptive(meaningful).
- We must not use space in variable name.
- A variable name must start with a letter or the underscore character.
- A variable name cannot start with a number or any special character like @,$, (, * % etc.
- Python reserved keywords cannot be used for naming the variable.
- Python variable names are case-sensitive which means Fee and FEE are two different variables in Python.