Variables

In programming languages, Variable in Python refers to an object — an item or element that is stored in the memory. Value of a variable can be a string (like ‘b’, ‘Global Citizen’), numeric (like 345) or any combination of alphanumeric characters (like 'CD67').

Rules for naming a Variable

  • The name should begin with an uppercase or a lowercase alphabet or an underscore sign (_). This may be any combination of characters a–z, A–Z, 0–9 or underscore (_). Thus, an identifier cannot start with a digit.
  • It can be of any length. However, it is preferred to keep it short and meaningful.
  • Space in between the words are not allowed as a variable.
  • It should not be a special keyword or reserved word.
  • We cannot use special symbols like !, @, #, $, % etc.

Examples

gender = 'Male'
message = "Hello India"
price = 987

Write a program to display values of variables in Python.

message = "Hello India"
print(message)
userNo = 12345
print(userNo)

Output:
Hello India
12345

Assigning values to a Variable

a = 1
b = 2
or
a,b = 1,2
Both have same meaning.