Prahlad Inala
Prahlad Inala

Prahlad Inala

Variables in Python

Variables in Python

Prahlad Inala
ยทJul 4, 2021ยท

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

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

  1. A variable can have a short name or a more descriptive name
  2. A variable name must start with a letter or the underscore character
  3. A variable name cannot start with a number
  4. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
  5. Variable names are case-sensitive (age, Age, and AGE are three different variables)
ย 
Share this