What are Variables in Python?
Variables are containers for storing data values. Unlike other programming languages, Python has no command for declaring a variable. A variable is created the moment you first assign a value to it.
General Example: Let us consider our lunch box, we can store any kind of food in it (that is no need to specify what is in it).
Example 1: Number (Integer)
x = 8
print(x)
#8
Example 2: String
y = "Madam"
print(y)
#Madam
Example 3: Overwriting Variable
z = 8 # z is of type int
z = "Madam" # z is now of type str
print(z)
#Madam
Rules to declare a variable
- A variable can have a short name or a more descriptive name
- A variable name must start with a letter or the underscore character
- A variable name 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 (age, Age, and AGE are three different variables)
ย