Class 12 : Review Of Python Basics

Home Page class 12 @ Python

Class 12 : Python

Python Basics
Data Types
String
List
Tuple
Dictionary
Flow of Execution
Mutable and Immutable Types
Type Casting

Class 12 : Python Revision MCQs

Revision Tour MCQs

Class 12 | Revision Tour : Operators

By: Archana Shukla and Rajesh Shukla

Operators

Operators are used to perform operations on variables and values.

Python divides the operators in the following groups:

Arithmetic operators : (+,-,*,/,%,**,//)

Addition (+) : To add two numbers. Example: 2+5=7, 3.5+3=6.5

Subtraction (-) : To subtract one value from the other. Example: 40-30 is 10

Multiplication (*) : To multiply numbers. Example: 3.5*2 is 7

Division (/) : To find the quotient. Example : 3/2 is 1.5

Floor division (//) :- To find the integer part of the quotient when one number is divided by another. Example : 3//2 is 1 or 10.0//3 is 3.0

Modulus (%) : It returns the remainder after diving one number by the other. Example : 5%2 is 1

Exponent(**): To raise the number to the power of the other. Example value of 3**2 or 32 is 9.

Assignment operators: (=,+=,-=,*=,/=,**=,//=,%=)

Add and assign(+=):

a=10
print(a)
a=a+10
print(a)
a=10
a+=10
print(a)

Output:

10
20
20

Subtract and assign(-=):

a=20
print(a)
a=a-10
print(a)
a=20
a-=10

Output:

20
10
10

Multiply and assign(*=):

a=10
print(a)
a=a*10 
print(a) 
a=10 
a*=10
print(a)

Output:

10
100
100

Divide and assign quotient(/=):

a=20
print(a)
a=a/10
print(a)
a=20
a/=10
print(a)

Output:

20
2.0
2.0

Divide and assign remainder(%=):

a=20
print(a)
a=a%10
print(a)
a=5
a%=2
print(a)

Output:
20
0
1

Floor division and assign(//=):

a=5
print(a)
a=a//2
print(a)
a=5
a//=2
print(a)

Output:
5
2
2

Exponent and assign(**=):

a=2
print(a)
a=a**2
print(a)
a=2
a**=2
print(a)

Output:
2
4
4

Number Of Visitors

0270459