Variables

Overview

Time: 0 min
Objectives
  • To understand variables and the rules of naming variables

What are Variables?

In python, we have constants and variables. A constant does not change its value over time. A variable is a container that is used to store values. The values of the variable can change in accordance to the manipulation being done on it.

How to create a Variable?

A variable is created the moment you assign a value to it.


name = "Recipe for pancakes"
no_of_ingredients = 5
print(no_of_ingredients)
print(name)

In python, we can also change the values assigned to the variables, without any restrictions.

no_of_ingredients = "Recipe for pancakes"    # x is now of type string
name = 5                       # name is now of type int
print(x)
print(name)

Policy for naming Variables

Variables in python should follow the given rules

Key Points