SlideShare a Scribd company logo
1 of 19
Download to read offline
Operators are functions that perform some
logical calculations.
Operators manipulate the value of the
operands.
Python supports several kinds of operators.
Arithmetic operators
Relational operators
Identity operators
Logical operators
Bitwise operators
Membership operators
Let us discuss one –by – one in detailed.
 Arithmetic operators are used with numeric
values to perform common mathematical
operations.
 Arithmetic operators are used for Addition,
subtraction, multiplication and division and so
on.
 Let us discuss them with an example.
Operator Description Example
Addition(+) Add values on either side of the operator A+B =9
Subtraction(-) Subtracts A from B A-B =3
Multiplication(*) Multiplies A with B A*B = 18
Division(/) Divides the denominator with numerator A/B =2
Modulus(%)
Performs the division operator and returns the
remainder
A%B=0
Exponent(**) Performs exponential calculation on operators
A**B= 6 power 3
=216
 These operator compares the operands and
displays the result.
 Let us assume a = 3 , b =5
Operator Description Example
Equal to (==) This operation returns true if two values are equal A==B returns False
Not equal to
(!=)
If the two operands are not equal this returns true A!=B returns true
Greater than
(>)
If the value of the left operand is greater than right this returns
true
A>B returns false
Less than (<)
This operator true if the left operand is less than the right
operand
A< B returns true
Greater than
or equal to
(>=)
This operator returns true if the left operand is greater than or
equal to the right operand
A>=B returns false
Less than or
equal to (<=)
This operator returns true if the left operand is less than or equal
to the right operand
A<=B returns True
 The Identity operators are used to check if both
the operands reference the same object
memory.
Operator Description Example
is
Returns true if both variables are the
same object
x is y
is not
Returns true if both variables are not
the same object
x is not y
The is not operator is opposite of is operator.
Let us take some examples
A = 10
B = 10
A is B #will return True because both are referencing the same
memory address.
A is not B #will return False because both are referencing the same
memory address.
 Logical operators are used for the logic
condition ( true (or) false).
 We have three types of logical operators.
Let a = 1, b = 2
Operator Example Meaning Result
And a and b If a is False returns
a
Otherwise returns b
2
Or A or b If a is false returns
b
Otherwise returns a
1
Not Not a If a is False returns
True
Otherwise returns
False
False
 Python Bitwise operators are used to perform
bit operations.
 All the decimal values will be converted into
binary values (sequence of bits i.e 0100, 1100,
1000, 1001 etc). Next, Python bitwise operators
will work on these bits such as shifting them
left to right or converting bit value from 0 to 1
etc.
 Let us discuss with an example A =30, B= 23
 These two numbers written in binary format as
 A = 30 = 0001 1110, B = 23 = 0001 0111.
Operator Description Example
And (&)
If both the inputs are True the result is True else the
result is False
A&B =22 (0001 0110)
Or(|)
If both the inputs are False the result is zero else the
result is True
A|B= 31(0001 1111)
Xor(^)
If both the bits are same the result is False else the
result is True
A^B =9(0000 1001)
Compliment(~) If the input is True the output is False and vice-versa A~B =-31(1000 1111)
 Membership operators are used to test if a sequence is
presented in an object.
 The membership operators are classified into two types.
 A={1 ,2,3,4,5}
Operator Description Example
Is
It returns true if the
value is found in the
sequence
5 in A returns True
10 in A returns False
Not in
True if the variable is
not found in the
sequence
5 not in A
returns False
10 not in
A returns True
 When there is several operations to be performed, operator precedence
determines which operator would be given importance over others.
 **
 ~+/~-
 */%//
 +-
 >><<
 &
 ^|
 <=< >>=
 <>==!=
 = -= +=//=%=/=*=*==
 Is, is not
 In in not
 Not or and
Python operators

More Related Content

What's hot (18)

Operators in c++
Operators in c++Operators in c++
Operators in c++
 
Operators
OperatorsOperators
Operators
 
Operator.ppt
Operator.pptOperator.ppt
Operator.ppt
 
Chapter 5 - Operators in C++
Chapter 5 - Operators in C++Chapter 5 - Operators in C++
Chapter 5 - Operators in C++
 
Operators
OperatorsOperators
Operators
 
Report on c
Report on cReport on c
Report on c
 
Relational operators
Relational operatorsRelational operators
Relational operators
 
Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressions
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Operators and Expressions
Operators and ExpressionsOperators and Expressions
Operators and Expressions
 
CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
 
itft-Operators in java
itft-Operators in javaitft-Operators in java
itft-Operators in java
 
Operators
OperatorsOperators
Operators
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
 
Operators and it's type
Operators and it's type Operators and it's type
Operators and it's type
 

Similar to Python operators (20)

Opeartor &amp; expression
Opeartor &amp; expressionOpeartor &amp; expression
Opeartor &amp; expression
 
Operator 04 (js)
Operator 04 (js)Operator 04 (js)
Operator 04 (js)
 
java operators
 java operators java operators
java operators
 
C programming operators
C programming operatorsC programming operators
C programming operators
 
Java basic operators
Java basic operatorsJava basic operators
Java basic operators
 
Java basic operators
Java basic operatorsJava basic operators
Java basic operators
 
11operator in c#
11operator in c#11operator in c#
11operator in c#
 
Session03 operators
Session03 operatorsSession03 operators
Session03 operators
 
Operators used in vb.net
Operators used in vb.netOperators used in vb.net
Operators used in vb.net
 
Conditional and special operators
Conditional and special operatorsConditional and special operators
Conditional and special operators
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
 
Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5
 
Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
 
C – operators and expressions
C – operators and expressionsC – operators and expressions
C – operators and expressions
 
Bit shift operators
Bit shift operatorsBit shift operators
Bit shift operators
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
 
Python basic operators
Python   basic operatorsPython   basic operators
Python basic operators
 
Operators
OperatorsOperators
Operators
 
COM1407: C Operators
COM1407: C OperatorsCOM1407: C Operators
COM1407: C Operators
 

More from nuripatidar

More from nuripatidar (9)

Python program
Python programPython program
Python program
 
Python lists
Python listsPython lists
Python lists
 
Tuple.py
Tuple.pyTuple.py
Tuple.py
 
Indian history
Indian historyIndian history
Indian history
 
Python basic Program
Python basic ProgramPython basic Program
Python basic Program
 
Python Programme list
Python Programme listPython Programme list
Python Programme list
 
Chemistry
ChemistryChemistry
Chemistry
 
Python statements
Python statementsPython statements
Python statements
 
Python data type
Python data typePython data type
Python data type
 

Recently uploaded

Geoffrey Chaucer Works II UGC NET JRF TGT PGT MA PHD Entrance Exam II History...
Geoffrey Chaucer Works II UGC NET JRF TGT PGT MA PHD Entrance Exam II History...Geoffrey Chaucer Works II UGC NET JRF TGT PGT MA PHD Entrance Exam II History...
Geoffrey Chaucer Works II UGC NET JRF TGT PGT MA PHD Entrance Exam II History...DrVipulVKapoor
 
CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...Nguyen Thanh Tu Collection
 
Sarah Lahm In Media Res Media Component
Sarah Lahm  In Media Res Media ComponentSarah Lahm  In Media Res Media Component
Sarah Lahm In Media Res Media ComponentInMediaRes1
 
How to create _name_search function in odoo 17
How to create _name_search function in odoo 17How to create _name_search function in odoo 17
How to create _name_search function in odoo 17Celine George
 
BÀI TẬP BỔ TRỢ 4 KĨ NĂNG TIẾNG ANH LỚP 11 (CẢ NĂM) - FRIENDS GLOBAL - NĂM HỌC...
BÀI TẬP BỔ TRỢ 4 KĨ NĂNG TIẾNG ANH LỚP 11 (CẢ NĂM) - FRIENDS GLOBAL - NĂM HỌC...BÀI TẬP BỔ TRỢ 4 KĨ NĂNG TIẾNG ANH LỚP 11 (CẢ NĂM) - FRIENDS GLOBAL - NĂM HỌC...
BÀI TẬP BỔ TRỢ 4 KĨ NĂNG TIẾNG ANH LỚP 11 (CẢ NĂM) - FRIENDS GLOBAL - NĂM HỌC...Nguyen Thanh Tu Collection
 
BBA 205 UNIT 3 INDUSTRIAL POLICY dr kanchan.pptx
BBA 205 UNIT 3 INDUSTRIAL POLICY dr kanchan.pptxBBA 205 UNIT 3 INDUSTRIAL POLICY dr kanchan.pptx
BBA 205 UNIT 3 INDUSTRIAL POLICY dr kanchan.pptxProf. Kanchan Kumari
 
DBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfDBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfChristalin Nelson
 
Sulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesSulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesVijayaLaxmi84
 
How to Uninstall a Module in Odoo 17 Using Command Line
How to Uninstall a Module in Odoo 17 Using Command LineHow to Uninstall a Module in Odoo 17 Using Command Line
How to Uninstall a Module in Odoo 17 Using Command LineCeline George
 
18. Training and prunning of horicultural crops.pptx
18. Training and prunning of horicultural crops.pptx18. Training and prunning of horicultural crops.pptx
18. Training and prunning of horicultural crops.pptxUmeshTimilsina1
 
6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroom6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroomSamsung Business USA
 
The Shop Floor Overview in the Odoo 17 ERP
The Shop Floor Overview in the Odoo 17 ERPThe Shop Floor Overview in the Odoo 17 ERP
The Shop Floor Overview in the Odoo 17 ERPCeline George
 
Jordan Chrietzberg In Media Res Media Component
Jordan Chrietzberg In Media Res Media ComponentJordan Chrietzberg In Media Res Media Component
Jordan Chrietzberg In Media Res Media ComponentInMediaRes1
 
Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...
Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...
Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...EduSkills OECD
 
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFEPART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFEMISSRITIMABIOLOGYEXP
 
Jason Potel In Media Res Media Component
Jason Potel In Media Res Media ComponentJason Potel In Media Res Media Component
Jason Potel In Media Res Media ComponentInMediaRes1
 
Pastoral Poetry, Definition, Origin, Characteristics and Examples
Pastoral Poetry, Definition, Origin, Characteristics and ExamplesPastoral Poetry, Definition, Origin, Characteristics and Examples
Pastoral Poetry, Definition, Origin, Characteristics and ExamplesDrVipulVKapoor
 

Recently uploaded (20)

Geoffrey Chaucer Works II UGC NET JRF TGT PGT MA PHD Entrance Exam II History...
Geoffrey Chaucer Works II UGC NET JRF TGT PGT MA PHD Entrance Exam II History...Geoffrey Chaucer Works II UGC NET JRF TGT PGT MA PHD Entrance Exam II History...
Geoffrey Chaucer Works II UGC NET JRF TGT PGT MA PHD Entrance Exam II History...
 
CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...
 
Sarah Lahm In Media Res Media Component
Sarah Lahm  In Media Res Media ComponentSarah Lahm  In Media Res Media Component
Sarah Lahm In Media Res Media Component
 
How to create _name_search function in odoo 17
How to create _name_search function in odoo 17How to create _name_search function in odoo 17
How to create _name_search function in odoo 17
 
Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...
Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...
Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...
 
BÀI TẬP BỔ TRỢ 4 KĨ NĂNG TIẾNG ANH LỚP 11 (CẢ NĂM) - FRIENDS GLOBAL - NĂM HỌC...
BÀI TẬP BỔ TRỢ 4 KĨ NĂNG TIẾNG ANH LỚP 11 (CẢ NĂM) - FRIENDS GLOBAL - NĂM HỌC...BÀI TẬP BỔ TRỢ 4 KĨ NĂNG TIẾNG ANH LỚP 11 (CẢ NĂM) - FRIENDS GLOBAL - NĂM HỌC...
BÀI TẬP BỔ TRỢ 4 KĨ NĂNG TIẾNG ANH LỚP 11 (CẢ NĂM) - FRIENDS GLOBAL - NĂM HỌC...
 
BBA 205 UNIT 3 INDUSTRIAL POLICY dr kanchan.pptx
BBA 205 UNIT 3 INDUSTRIAL POLICY dr kanchan.pptxBBA 205 UNIT 3 INDUSTRIAL POLICY dr kanchan.pptx
BBA 205 UNIT 3 INDUSTRIAL POLICY dr kanchan.pptx
 
Israel Genealogy Research Assoc. April 2024 Database Release
Israel Genealogy Research Assoc. April 2024 Database ReleaseIsrael Genealogy Research Assoc. April 2024 Database Release
Israel Genealogy Research Assoc. April 2024 Database Release
 
DBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfDBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdf
 
Sulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesSulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their uses
 
How to Uninstall a Module in Odoo 17 Using Command Line
How to Uninstall a Module in Odoo 17 Using Command LineHow to Uninstall a Module in Odoo 17 Using Command Line
How to Uninstall a Module in Odoo 17 Using Command Line
 
CARNAVAL COM MAGIA E EUFORIA _
CARNAVAL COM MAGIA E EUFORIA            _CARNAVAL COM MAGIA E EUFORIA            _
CARNAVAL COM MAGIA E EUFORIA _
 
18. Training and prunning of horicultural crops.pptx
18. Training and prunning of horicultural crops.pptx18. Training and prunning of horicultural crops.pptx
18. Training and prunning of horicultural crops.pptx
 
6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroom6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroom
 
The Shop Floor Overview in the Odoo 17 ERP
The Shop Floor Overview in the Odoo 17 ERPThe Shop Floor Overview in the Odoo 17 ERP
The Shop Floor Overview in the Odoo 17 ERP
 
Jordan Chrietzberg In Media Res Media Component
Jordan Chrietzberg In Media Res Media ComponentJordan Chrietzberg In Media Res Media Component
Jordan Chrietzberg In Media Res Media Component
 
Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...
Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...
Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...
 
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFEPART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
 
Jason Potel In Media Res Media Component
Jason Potel In Media Res Media ComponentJason Potel In Media Res Media Component
Jason Potel In Media Res Media Component
 
Pastoral Poetry, Definition, Origin, Characteristics and Examples
Pastoral Poetry, Definition, Origin, Characteristics and ExamplesPastoral Poetry, Definition, Origin, Characteristics and Examples
Pastoral Poetry, Definition, Origin, Characteristics and Examples
 

Python operators

  • 1.
  • 2.
  • 3. Operators are functions that perform some logical calculations. Operators manipulate the value of the operands. Python supports several kinds of operators.
  • 4. Arithmetic operators Relational operators Identity operators Logical operators Bitwise operators Membership operators
  • 5. Let us discuss one –by – one in detailed.
  • 6.  Arithmetic operators are used with numeric values to perform common mathematical operations.  Arithmetic operators are used for Addition, subtraction, multiplication and division and so on.  Let us discuss them with an example.
  • 7. Operator Description Example Addition(+) Add values on either side of the operator A+B =9 Subtraction(-) Subtracts A from B A-B =3 Multiplication(*) Multiplies A with B A*B = 18 Division(/) Divides the denominator with numerator A/B =2 Modulus(%) Performs the division operator and returns the remainder A%B=0 Exponent(**) Performs exponential calculation on operators A**B= 6 power 3 =216
  • 8.  These operator compares the operands and displays the result.
  • 9.  Let us assume a = 3 , b =5 Operator Description Example Equal to (==) This operation returns true if two values are equal A==B returns False Not equal to (!=) If the two operands are not equal this returns true A!=B returns true Greater than (>) If the value of the left operand is greater than right this returns true A>B returns false Less than (<) This operator true if the left operand is less than the right operand A< B returns true Greater than or equal to (>=) This operator returns true if the left operand is greater than or equal to the right operand A>=B returns false Less than or equal to (<=) This operator returns true if the left operand is less than or equal to the right operand A<=B returns True
  • 10.  The Identity operators are used to check if both the operands reference the same object memory. Operator Description Example is Returns true if both variables are the same object x is y is not Returns true if both variables are not the same object x is not y The is not operator is opposite of is operator.
  • 11. Let us take some examples A = 10 B = 10 A is B #will return True because both are referencing the same memory address. A is not B #will return False because both are referencing the same memory address.
  • 12.  Logical operators are used for the logic condition ( true (or) false).  We have three types of logical operators.
  • 13. Let a = 1, b = 2 Operator Example Meaning Result And a and b If a is False returns a Otherwise returns b 2 Or A or b If a is false returns b Otherwise returns a 1 Not Not a If a is False returns True Otherwise returns False False
  • 14.  Python Bitwise operators are used to perform bit operations.  All the decimal values will be converted into binary values (sequence of bits i.e 0100, 1100, 1000, 1001 etc). Next, Python bitwise operators will work on these bits such as shifting them left to right or converting bit value from 0 to 1 etc.
  • 15.  Let us discuss with an example A =30, B= 23  These two numbers written in binary format as  A = 30 = 0001 1110, B = 23 = 0001 0111. Operator Description Example And (&) If both the inputs are True the result is True else the result is False A&B =22 (0001 0110) Or(|) If both the inputs are False the result is zero else the result is True A|B= 31(0001 1111) Xor(^) If both the bits are same the result is False else the result is True A^B =9(0000 1001) Compliment(~) If the input is True the output is False and vice-versa A~B =-31(1000 1111)
  • 16.  Membership operators are used to test if a sequence is presented in an object.
  • 17.  The membership operators are classified into two types.  A={1 ,2,3,4,5} Operator Description Example Is It returns true if the value is found in the sequence 5 in A returns True 10 in A returns False Not in True if the variable is not found in the sequence 5 not in A returns False 10 not in A returns True
  • 18.  When there is several operations to be performed, operator precedence determines which operator would be given importance over others.  **  ~+/~-  */%//  +-  >><<  &  ^|  <=< >>=  <>==!=  = -= +=//=%=/=*=*==  Is, is not  In in not  Not or and