Variables in Python
A variable is a container used to store data values. In Python, you don’t need to declare the type of a variable, it is automatically assigned.
Example:
name = "Aman"
age = 20
height = 5.8
print(name)
print(age)
print(height)Rules for naming variables:
- Must start with a letter or underscore (
_)
- Must start with a letter or underscore (
- Cannot start with a number
- Cannot use keywords (like
if,for,while) # will learn about keywords in upcoming topics
- Cannot use keywords (like
- Case-sensitive (
Nameandnameare different)
- Case-sensitive (
x = 5
5x = 7 # wrong
x5 = 8
_g = 9