Page 66 - KEC Khaitan C7 Flipbook
P. 66
Tick ( ) if you know this.
▶ Python is an interpreted language that executes code line by line.
▶ The Python Shell window executes one command at a time.
VARIABLES IN PYTHON
A Variable is the name of the memory location that is used to store data values that can be
accessed or changed later. The names given to the variables are known as identifiers. In Python,
we do not need to specify the type of variable because Python is a dynamic language and it also
identifies the variable type automatically.
DECLARING AND INITIALISING A VARIABLE
In Python, variables are declared and initialised at the same time in the following way:
a = 10
b = 20
print ("+a=", a)
print ("b=", b)
On the output screen, a = 10 and b = 20 will be printed. You can also assign the same value
to multiple variables at the same time in the following way:
a = b = 20
print ("a=", a)
print ("b=", b)
On the output screen, a = 20 and b = 20 will be printed.
You can also assign multiple values to multiple variables in the same line in the following way:
name, age, Class= "Anaya", 12, 'VII'
print ("Name is", name)
print ("Age is", age)
print ("Grade is", Class)
On the output screen, Name is Anaya, Age is 12, and Grade is VII will be printed in
three lines.
You must follow the given rules while creating and naming the variables:
A variable name must start with a letter or underscore character.
A variable name cannot start with a number.
A variable name can only contain alphanumeric characters (all the letters of the alphabet and
numbers) and underscores (_).
Variable names are case-sensitive.
Variable names cannot contain any special character or symbol.
64 Premium Edition-VII

