SlideShare a Scribd company logo
2
Most read
5
Most read
6
Most read
Operators in Python
All the operators in Python are classified according to their nature and
type and they are:
• Arithmetic Operators
• Relational Operators
• Logical Operators
• Assignment Operators
• Bitwise Operators
• Boolean Operators
• Membership Operators
• Identity Operators
Arithmetic Operators
• These operators perform basic arithmetic operations like addition,
subtraction, multiplication, division etc. and these operators are
binary operators that means these operators acts on two operands.
And there are 7 binary arithmetic operators available in Python.
Operator Meaning Example Result
+ Addition 10 + 7 12
- Subtraction 10.0 - 1.5 8.5
* Multiplication 30 * 3 900
/ Float Division 5 / 2 2.5
// Integer Division 5 // 2 2
** Exponentiation 3 ** 2 9
% Remainder 10 % 3 1
Operator Priority
Parenthesis (( ), [ ]) First
Exponentiation (**) Second
Multiplication (*), Division (/, //), Modulus (%) Third
Addition (+), Subtraction (-) Fourth
Assignment Fifth
Relational Operators
• Relational operators are used for comparison and the output is either
True or False depending on the values we compare. The following
table shows the list of relational operators with example.
Operator Meaning Example Result
< Less than 5 < 7 True
> Greater than 9 > 5 True
<= Less than equal to 8 <= 8 True
>= Greater than equal
to
7 >= 9 False
== Equal to 10 == 20 False
!= Not equal to 9 != 6 True
Logical Operators
• Logical operators are used to form compound conditions which are a
combination of more than one simple condition. Each of the simple
conditions are evaluated first and based on the result compound
condition is evaluated. The result of the expression is either True or
False based on the result of simple conditions.
Operator Meaning Example Result
and Logical AND (5 > 7) and (3 < 5) False
or Logical OR (7 == 7) or (5 != 5) True
not Logical NOT not(3 <= 2) True
Assignment Operators
• These operators are used to store a value into a variable and also useful to
perform simple arithmetic operations. Assignment operators are of two
types: simple assignment operator and augmented assignment operator.
Simple assignment operators are combined with arithmetic operators to form
augmented assignment operators. The following table shows a list of
assignment operators and its use.
Operator Meaning Example Result
= Simple assignment a = 10 10
+= Addition assignment a = 5
a += 8
13
-= Subtraction assignment b = 5
b -= 8
-3
*= Multiplication assignment a =10
a *= 8
80
/= Float Division assignment a = 10
a /= 8
1.25
//= Integer Division assignment b = 10
b //= 10
1
**= Exponentiation assignment a = 10
a %= 5
0
%= Remainder assignment b = 10
b ** = 8
100000000
Bitwise Operators
• Bitwise Operators acts on individual bits of the operands. These
operators directly act on binary numbers. If we want to use these
operators on integers then first these numbers are converted into
binary numbers and then bitwise operators act on those bits. The
following table shows the list of bitwise operators available in Python.
Operator Meaning Example Result
& Bitwise AND a = 10 = 0000 1010
b = 11 = 0000 1011
a & b = 0000 1010 = 10
a & b = 10
| Bitwise OR a = 10 = 0000 1010
b = 11 = 0000 1011
a | b = 0000 1011 = 11
a | b = 11
^ Bitwise XOR a = 10 = 0000 1010
b = 11 = 0000 1011
a ^ b = 0000 0001 = 1
a ^ b = 1
~ Bitwise Complement a = 10 = 0000 1010
~a = 1111 0101 = -11
~a = -11
<< Bitwise Left Shift a = 10
a << 2 = 40
a << 2 = 40
>> Bitwise Right Shift a = 10
a >> 2 = 2
a >> 2 = 2
Boolean Operators
• There are three boolean operators that act on bool type
literals and provide bool type output. The result of the
boolean operators are either True or False.
Operator Meaning Example Result
and Boolean
AND
a = True, b = False
a and b = True and
False
a and b = False
or Boolean OR a = True, b = False
a or b = True or
False
a or b = True
not Boolean
NOT
a = True
not a = not True
not a = False
Membership Operators
There are two membership operators in Python that are useful to test for
membership in a sequence.
• in: This operator returns True if an element is found in the specified
sequence, otherwise it returns False.
• not in: This operator returns True if any element is not found in the
sequence, otherwise it returns True.
Identity Operators
These operators are used to compare the memory locations of two objects.
Therefore it is possible to verify whether the two objects are same or not. In
Python id() function gives the memory location of an object. Example id(a)
returns the identity number or memory location of object a. There are two
identity operators available in Python. They are
• is: This operator is used to compare the memory location of two objects. If
they are same then it returns True, otherwise returns False.
• is not: This operator returns True if the memory locations of two objects are
not same.If they are same then it returns False.
Operator Precedence and Associativity
• An expression may contain several operators and the order in which
these operators are executed in sequence is called operator
precedence. The following table summarizes the operators in
descending order of their precedence.
Operator Name Precedence
( ) Parenthesis 1st
** Exponentiation 2nd
-, ~ Unary minus, bitwise complement 3rd
*, /, //, % Multiplication, Division, Floor Division, Modulus 4th
+, - Addition, Subtraction 5th
<<, >> Bitwise left shift, bitwise right shift 6th
& Bitwise AND 7th
^ Bitwise XOR 8th
| Bitwise OR 9th
>, >=, <, <=, = =, != Relational Operators 10th
=, %=, /=, //=, -=, +=, *=, **= Assignment Operators 11th
is, is not Identity Operators 12th
in, not in Membership Operators 13th
not Logical NOT 14th
or Logical OR 15th
and Logical AND 16th
Single Line and Multiline Comments
• There are two types of comments used in Python:
• Single Line Comments: These are created simply by starting a line with the hash
character (#), and they are automatically terminated by the end of line. If a line
using the hash character (#) is written after the Python statement, then it is
known as inline comment.
• Multiline Comments: When multiple lines are used as comment lines, then
writing hash character (#) in the beginning of every line is a tedious task. So
instead of writing # character in the beginning of every line, we can enclose
multiple comment lines within ''' (triple single quotes) or """ (triple double
quotes). Multi line comments are also known as block comments.
INPUT AND OUTPUT
• The purpose of a computer is to process data and return results.The data
given to the computer is called input. The results returned by the
computer are called output. So, we can say that a computer takes input,
processes that input and produces the output.

More Related Content

PDF
Lesson 03 python statement, indentation and comments
Nilimesh Halder
 
PDF
Python If Else | If Else Statement In Python | Edureka
Edureka!
 
PPTX
Hidden surface removal
Ankit Garg
 
PPTX
Functions in C.pptx
Ashwini Raut
 
DOCX
Tally unit 4
Dr T.Sivakami
 
PPTX
Pointers in c++
Rajat Busheheri
 
PPTX
Operators and Expressions
Munazza-Mah-Jabeen
 
PDF
Unit 3
ypnrao
 
Lesson 03 python statement, indentation and comments
Nilimesh Halder
 
Python If Else | If Else Statement In Python | Edureka
Edureka!
 
Hidden surface removal
Ankit Garg
 
Functions in C.pptx
Ashwini Raut
 
Tally unit 4
Dr T.Sivakami
 
Pointers in c++
Rajat Busheheri
 
Operators and Expressions
Munazza-Mah-Jabeen
 
Unit 3
ypnrao
 

What's hot (20)

PPTX
Overview of c language
shalini392
 
PDF
Operator overloading
Pranali Chaudhari
 
PPTX
Python programming | Fundamentals of Python programming
KrishnaMildain
 
PPTX
3 d display methods
Shami Al Rahad
 
PPTX
File in C language
Manash Kumar Mondal
 
PPT
LR-Parsing.ppt
BapanKar2
 
PDF
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
PPSX
Programming with Python
Rasan Samarasinghe
 
PPSX
C++ Programming Language
Mohamed Loey
 
PDF
Computer graphics curves and surfaces (1)
RohitK71
 
PPT
FUNCTIONS IN c++ PPT
03062679929
 
PPTX
Python Exception Handling
Megha V
 
PDF
Arrays in C++
Maliha Mehr
 
PPT
Decision making and looping
Hossain Md Shakhawat
 
PPT
Basics of c++ Programming Language
Ahmad Idrees
 
PPTX
Tree - Data Structure
Ashim Lamichhane
 
PPTX
Basic data types in python
sunilchute1
 
PPTX
1.10. pumping lemma for regular sets
Sampath Kumar S
 
Overview of c language
shalini392
 
Operator overloading
Pranali Chaudhari
 
Python programming | Fundamentals of Python programming
KrishnaMildain
 
3 d display methods
Shami Al Rahad
 
File in C language
Manash Kumar Mondal
 
LR-Parsing.ppt
BapanKar2
 
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
Programming with Python
Rasan Samarasinghe
 
C++ Programming Language
Mohamed Loey
 
Computer graphics curves and surfaces (1)
RohitK71
 
FUNCTIONS IN c++ PPT
03062679929
 
Python Exception Handling
Megha V
 
Arrays in C++
Maliha Mehr
 
Decision making and looping
Hossain Md Shakhawat
 
Basics of c++ Programming Language
Ahmad Idrees
 
Tree - Data Structure
Ashim Lamichhane
 
Basic data types in python
sunilchute1
 
1.10. pumping lemma for regular sets
Sampath Kumar S
 
Ad

Similar to Operators in Python Arithmetic Operators (20)

PPTX
Operators Concept in Python-N.Kavitha.pptx
Kavitha713564
 
PPTX
Operators in Python
Anusuya123
 
PDF
Python basic operators
Learnbay Datascience
 
PPTX
PYTHON OPERATORS 123Python Operators.pptx
AnjaneyuluKunchala1
 
PPTX
Python programming language introduction unit
michaelaaron25322
 
PPTX
Python Operators
Adheetha O. V
 
PPTX
Python Lec-6 Operatorguijjjjuugggggs.pptx
ks812227
 
PDF
Python : basic operators
S.M. Salaquzzaman
 
PPTX
Python operators
nuripatidar
 
PPTX
OPERATORS-PYTHON.pptx ALL OPERATORS ARITHMATIC AND LOGICAL
NagarathnaRajur2
 
PPTX
Python Programming | JNTUK | UNIT 1 | Lecture 5
FabMinds
 
PDF
Python Basic Operators
Soba Arjun
 
PPTX
Python_Module_3_AFkkkkV_Operators-1.pptx
tissot723
 
PPTX
1 Standard Data types.pptx
ssuser8e50d8
 
PDF
Operators_in_Python_Simplified_languages
AbhishekGupta692777
 
PPTX
Python tutorials for beginners | IQ Online Training
Rahul Tandale
 
PPTX
operatorsinpython-18112209560412 (1).pptx
urvashipundir04
 
PPSX
Python Data Types, Operators and Control Flow
Dr. A. B. Shinde
 
PPTX
python statement, expressions and operators.pptx
richumt
 
PPTX
Python notes for students to develop and learn
kavithaadhilakshmi
 
Operators Concept in Python-N.Kavitha.pptx
Kavitha713564
 
Operators in Python
Anusuya123
 
Python basic operators
Learnbay Datascience
 
PYTHON OPERATORS 123Python Operators.pptx
AnjaneyuluKunchala1
 
Python programming language introduction unit
michaelaaron25322
 
Python Operators
Adheetha O. V
 
Python Lec-6 Operatorguijjjjuugggggs.pptx
ks812227
 
Python : basic operators
S.M. Salaquzzaman
 
Python operators
nuripatidar
 
OPERATORS-PYTHON.pptx ALL OPERATORS ARITHMATIC AND LOGICAL
NagarathnaRajur2
 
Python Programming | JNTUK | UNIT 1 | Lecture 5
FabMinds
 
Python Basic Operators
Soba Arjun
 
Python_Module_3_AFkkkkV_Operators-1.pptx
tissot723
 
1 Standard Data types.pptx
ssuser8e50d8
 
Operators_in_Python_Simplified_languages
AbhishekGupta692777
 
Python tutorials for beginners | IQ Online Training
Rahul Tandale
 
operatorsinpython-18112209560412 (1).pptx
urvashipundir04
 
Python Data Types, Operators and Control Flow
Dr. A. B. Shinde
 
python statement, expressions and operators.pptx
richumt
 
Python notes for students to develop and learn
kavithaadhilakshmi
 
Ad

Recently uploaded (20)

PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
PDF
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PPTX
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PPT
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PPTX
Trends in pediatric nursing .pptx
AneetaSharma15
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PPTX
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
Trends in pediatric nursing .pptx
AneetaSharma15
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 

Operators in Python Arithmetic Operators

  • 1. Operators in Python All the operators in Python are classified according to their nature and type and they are: • Arithmetic Operators • Relational Operators • Logical Operators • Assignment Operators • Bitwise Operators • Boolean Operators • Membership Operators • Identity Operators
  • 2. Arithmetic Operators • These operators perform basic arithmetic operations like addition, subtraction, multiplication, division etc. and these operators are binary operators that means these operators acts on two operands. And there are 7 binary arithmetic operators available in Python. Operator Meaning Example Result + Addition 10 + 7 12 - Subtraction 10.0 - 1.5 8.5 * Multiplication 30 * 3 900 / Float Division 5 / 2 2.5 // Integer Division 5 // 2 2 ** Exponentiation 3 ** 2 9 % Remainder 10 % 3 1 Operator Priority Parenthesis (( ), [ ]) First Exponentiation (**) Second Multiplication (*), Division (/, //), Modulus (%) Third Addition (+), Subtraction (-) Fourth Assignment Fifth
  • 3. Relational Operators • Relational operators are used for comparison and the output is either True or False depending on the values we compare. The following table shows the list of relational operators with example. Operator Meaning Example Result < Less than 5 < 7 True > Greater than 9 > 5 True <= Less than equal to 8 <= 8 True >= Greater than equal to 7 >= 9 False == Equal to 10 == 20 False != Not equal to 9 != 6 True
  • 4. Logical Operators • Logical operators are used to form compound conditions which are a combination of more than one simple condition. Each of the simple conditions are evaluated first and based on the result compound condition is evaluated. The result of the expression is either True or False based on the result of simple conditions. Operator Meaning Example Result and Logical AND (5 > 7) and (3 < 5) False or Logical OR (7 == 7) or (5 != 5) True not Logical NOT not(3 <= 2) True
  • 5. Assignment Operators • These operators are used to store a value into a variable and also useful to perform simple arithmetic operations. Assignment operators are of two types: simple assignment operator and augmented assignment operator. Simple assignment operators are combined with arithmetic operators to form augmented assignment operators. The following table shows a list of assignment operators and its use. Operator Meaning Example Result = Simple assignment a = 10 10 += Addition assignment a = 5 a += 8 13 -= Subtraction assignment b = 5 b -= 8 -3 *= Multiplication assignment a =10 a *= 8 80 /= Float Division assignment a = 10 a /= 8 1.25 //= Integer Division assignment b = 10 b //= 10 1 **= Exponentiation assignment a = 10 a %= 5 0 %= Remainder assignment b = 10 b ** = 8 100000000
  • 6. Bitwise Operators • Bitwise Operators acts on individual bits of the operands. These operators directly act on binary numbers. If we want to use these operators on integers then first these numbers are converted into binary numbers and then bitwise operators act on those bits. The following table shows the list of bitwise operators available in Python. Operator Meaning Example Result & Bitwise AND a = 10 = 0000 1010 b = 11 = 0000 1011 a & b = 0000 1010 = 10 a & b = 10 | Bitwise OR a = 10 = 0000 1010 b = 11 = 0000 1011 a | b = 0000 1011 = 11 a | b = 11 ^ Bitwise XOR a = 10 = 0000 1010 b = 11 = 0000 1011 a ^ b = 0000 0001 = 1 a ^ b = 1 ~ Bitwise Complement a = 10 = 0000 1010 ~a = 1111 0101 = -11 ~a = -11 << Bitwise Left Shift a = 10 a << 2 = 40 a << 2 = 40 >> Bitwise Right Shift a = 10 a >> 2 = 2 a >> 2 = 2
  • 7. Boolean Operators • There are three boolean operators that act on bool type literals and provide bool type output. The result of the boolean operators are either True or False. Operator Meaning Example Result and Boolean AND a = True, b = False a and b = True and False a and b = False or Boolean OR a = True, b = False a or b = True or False a or b = True not Boolean NOT a = True not a = not True not a = False
  • 8. Membership Operators There are two membership operators in Python that are useful to test for membership in a sequence. • in: This operator returns True if an element is found in the specified sequence, otherwise it returns False. • not in: This operator returns True if any element is not found in the sequence, otherwise it returns True.
  • 9. Identity Operators These operators are used to compare the memory locations of two objects. Therefore it is possible to verify whether the two objects are same or not. In Python id() function gives the memory location of an object. Example id(a) returns the identity number or memory location of object a. There are two identity operators available in Python. They are • is: This operator is used to compare the memory location of two objects. If they are same then it returns True, otherwise returns False. • is not: This operator returns True if the memory locations of two objects are not same.If they are same then it returns False.
  • 10. Operator Precedence and Associativity • An expression may contain several operators and the order in which these operators are executed in sequence is called operator precedence. The following table summarizes the operators in descending order of their precedence. Operator Name Precedence ( ) Parenthesis 1st ** Exponentiation 2nd -, ~ Unary minus, bitwise complement 3rd *, /, //, % Multiplication, Division, Floor Division, Modulus 4th +, - Addition, Subtraction 5th <<, >> Bitwise left shift, bitwise right shift 6th & Bitwise AND 7th ^ Bitwise XOR 8th | Bitwise OR 9th >, >=, <, <=, = =, != Relational Operators 10th =, %=, /=, //=, -=, +=, *=, **= Assignment Operators 11th is, is not Identity Operators 12th in, not in Membership Operators 13th not Logical NOT 14th or Logical OR 15th and Logical AND 16th
  • 11. Single Line and Multiline Comments • There are two types of comments used in Python: • Single Line Comments: These are created simply by starting a line with the hash character (#), and they are automatically terminated by the end of line. If a line using the hash character (#) is written after the Python statement, then it is known as inline comment. • Multiline Comments: When multiple lines are used as comment lines, then writing hash character (#) in the beginning of every line is a tedious task. So instead of writing # character in the beginning of every line, we can enclose multiple comment lines within ''' (triple single quotes) or """ (triple double quotes). Multi line comments are also known as block comments.
  • 12. INPUT AND OUTPUT • The purpose of a computer is to process data and return results.The data given to the computer is called input. The results returned by the computer are called output. So, we can say that a computer takes input, processes that input and produces the output.