SlideShare a Scribd company logo
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.
Ad

More Related Content

What's hot (20)

Raw- Research & Analysis Wing
Raw- Research & Analysis WingRaw- Research & Analysis Wing
Raw- Research & Analysis Wing
Nivin Vinoi
 
Types of Hacker
 Types of Hacker Types of Hacker
Types of Hacker
Mukund Kumar Bharti
 
Cyber Crime
Cyber CrimeCyber Crime
Cyber Crime
Darshan Vithani
 
Cyber Forensics Module 2
Cyber Forensics Module 2Cyber Forensics Module 2
Cyber Forensics Module 2
Manu Mathew Cherian
 
DEVELOPMENT OF FINGERPRINTS
DEVELOPMENT OF FINGERPRINTSDEVELOPMENT OF FINGERPRINTS
DEVELOPMENT OF FINGERPRINTS
Don Caeiro
 
Fiber examination.pptx
Fiber examination.pptxFiber examination.pptx
Fiber examination.pptx
Suchita Rawat
 
Incident response methodology
Incident response methodologyIncident response methodology
Incident response methodology
Piyush Jain
 
Encase Forensic
Encase ForensicEncase Forensic
Encase Forensic
Megha Sahu
 
Introduction to Cyber Forensics Module 1
Introduction to Cyber Forensics Module 1Introduction to Cyber Forensics Module 1
Introduction to Cyber Forensics Module 1
Anpumathews
 
Paint analysis
Paint analysisPaint analysis
Paint analysis
Lovelesh Gangil
 
Crime Scene Management: First Responding Officer
Crime Scene Management: First Responding OfficerCrime Scene Management: First Responding Officer
Crime Scene Management: First Responding Officer
Mayank Raiborde
 
CCTNS
CCTNS CCTNS
CCTNS
Jayakumar PP
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
somendra kumar
 
Python for loop
Python for loopPython for loop
Python for loop
Aishwarya Deshmukh
 
Operators in python
Operators in pythonOperators in python
Operators in python
deepalishinkar1
 
Compound Microscope and Its Forensic Applications
Compound Microscope and Its Forensic Applications Compound Microscope and Its Forensic Applications
Compound Microscope and Its Forensic Applications
Parth Chuahan
 
Security features of currency note
Security features of currency noteSecurity features of currency note
Security features of currency note
anand8095
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
RaginiJain21
 
Gunshot residue, forensic analysis and interpretation ppt 03
Gunshot residue, forensic analysis and interpretation ppt 03Gunshot residue, forensic analysis and interpretation ppt 03
Gunshot residue, forensic analysis and interpretation ppt 03
SURYAKANT MISHRA
 
Cyber Forensics Overview
Cyber Forensics OverviewCyber Forensics Overview
Cyber Forensics Overview
Yansi Keim
 
Raw- Research & Analysis Wing
Raw- Research & Analysis WingRaw- Research & Analysis Wing
Raw- Research & Analysis Wing
Nivin Vinoi
 
DEVELOPMENT OF FINGERPRINTS
DEVELOPMENT OF FINGERPRINTSDEVELOPMENT OF FINGERPRINTS
DEVELOPMENT OF FINGERPRINTS
Don Caeiro
 
Fiber examination.pptx
Fiber examination.pptxFiber examination.pptx
Fiber examination.pptx
Suchita Rawat
 
Incident response methodology
Incident response methodologyIncident response methodology
Incident response methodology
Piyush Jain
 
Encase Forensic
Encase ForensicEncase Forensic
Encase Forensic
Megha Sahu
 
Introduction to Cyber Forensics Module 1
Introduction to Cyber Forensics Module 1Introduction to Cyber Forensics Module 1
Introduction to Cyber Forensics Module 1
Anpumathews
 
Crime Scene Management: First Responding Officer
Crime Scene Management: First Responding OfficerCrime Scene Management: First Responding Officer
Crime Scene Management: First Responding Officer
Mayank Raiborde
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
somendra kumar
 
Compound Microscope and Its Forensic Applications
Compound Microscope and Its Forensic Applications Compound Microscope and Its Forensic Applications
Compound Microscope and Its Forensic Applications
Parth Chuahan
 
Security features of currency note
Security features of currency noteSecurity features of currency note
Security features of currency note
anand8095
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
RaginiJain21
 
Gunshot residue, forensic analysis and interpretation ppt 03
Gunshot residue, forensic analysis and interpretation ppt 03Gunshot residue, forensic analysis and interpretation ppt 03
Gunshot residue, forensic analysis and interpretation ppt 03
SURYAKANT MISHRA
 
Cyber Forensics Overview
Cyber Forensics OverviewCyber Forensics Overview
Cyber Forensics Overview
Yansi Keim
 

Similar to Operators in Python Arithmetic Operators (20)

Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++
Praveen M Jigajinni
 
Python Programming | JNTUK | UNIT 1 | Lecture 5
Python Programming | JNTUK | UNIT 1 | Lecture 5Python Programming | JNTUK | UNIT 1 | Lecture 5
Python Programming | JNTUK | UNIT 1 | Lecture 5
FabMinds
 
Operators in python
Operators in pythonOperators in python
Operators in python
Prabhakaran V M
 
operators and expressions in c++
 operators and expressions in c++ operators and expressions in c++
operators and expressions in c++
sanya6900
 
Python programming language introduction unit
Python programming language introduction unitPython programming language introduction unit
Python programming language introduction unit
michaelaaron25322
 
Grade XI - Computer science Data Handling in Python
Grade XI - Computer science Data Handling in PythonGrade XI - Computer science Data Handling in Python
Grade XI - Computer science Data Handling in Python
vidyuthno1
 
Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
Thesis Scientist Private Limited
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statements
CtOlaf
 
1 Standard Data types.pptx
1 Standard Data types.pptx1 Standard Data types.pptx
1 Standard Data types.pptx
ssuser8e50d8
 
Operators
OperatorsOperators
Operators
Kamran
 
hlukj6;lukm,t.mnjhgjukryopkiu;lyk y2.ppt
hlukj6;lukm,t.mnjhgjukryopkiu;lyk y2.ppthlukj6;lukm,t.mnjhgjukryopkiu;lyk y2.ppt
hlukj6;lukm,t.mnjhgjukryopkiu;lyk y2.ppt
PraveenaFppt
 
Py-Slides-2 (1).ppt
Py-Slides-2 (1).pptPy-Slides-2 (1).ppt
Py-Slides-2 (1).ppt
KalaiVani395886
 
Py-Slides-2.ppt
Py-Slides-2.pptPy-Slides-2.ppt
Py-Slides-2.ppt
TejaValmiki
 
Py-Slides-2.ppt
Py-Slides-2.pptPy-Slides-2.ppt
Py-Slides-2.ppt
AllanGuevarra1
 
03 Operators and expressions
03 Operators and expressions03 Operators and expressions
03 Operators and expressions
maznabili
 
Operators_in_Python_Simplified_languages
Operators_in_Python_Simplified_languagesOperators_in_Python_Simplified_languages
Operators_in_Python_Simplified_languages
AbhishekGupta692777
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
Anusuya123
 
Coper in C
Coper in CCoper in C
Coper in C
thirumalaikumar3
 
Lecture 05.pptx
Lecture 05.pptxLecture 05.pptx
Lecture 05.pptx
Mohammad Hassan
 
Python_Module_3_AFkkkkV_Operators-1.pptx
Python_Module_3_AFkkkkV_Operators-1.pptxPython_Module_3_AFkkkkV_Operators-1.pptx
Python_Module_3_AFkkkkV_Operators-1.pptx
tissot723
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++
Praveen M Jigajinni
 
Python Programming | JNTUK | UNIT 1 | Lecture 5
Python Programming | JNTUK | UNIT 1 | Lecture 5Python Programming | JNTUK | UNIT 1 | Lecture 5
Python Programming | JNTUK | UNIT 1 | Lecture 5
FabMinds
 
operators and expressions in c++
 operators and expressions in c++ operators and expressions in c++
operators and expressions in c++
sanya6900
 
Python programming language introduction unit
Python programming language introduction unitPython programming language introduction unit
Python programming language introduction unit
michaelaaron25322
 
Grade XI - Computer science Data Handling in Python
Grade XI - Computer science Data Handling in PythonGrade XI - Computer science Data Handling in Python
Grade XI - Computer science Data Handling in Python
vidyuthno1
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statements
CtOlaf
 
1 Standard Data types.pptx
1 Standard Data types.pptx1 Standard Data types.pptx
1 Standard Data types.pptx
ssuser8e50d8
 
Operators
OperatorsOperators
Operators
Kamran
 
hlukj6;lukm,t.mnjhgjukryopkiu;lyk y2.ppt
hlukj6;lukm,t.mnjhgjukryopkiu;lyk y2.ppthlukj6;lukm,t.mnjhgjukryopkiu;lyk y2.ppt
hlukj6;lukm,t.mnjhgjukryopkiu;lyk y2.ppt
PraveenaFppt
 
03 Operators and expressions
03 Operators and expressions03 Operators and expressions
03 Operators and expressions
maznabili
 
Operators_in_Python_Simplified_languages
Operators_in_Python_Simplified_languagesOperators_in_Python_Simplified_languages
Operators_in_Python_Simplified_languages
AbhishekGupta692777
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
Anusuya123
 
Python_Module_3_AFkkkkV_Operators-1.pptx
Python_Module_3_AFkkkkV_Operators-1.pptxPython_Module_3_AFkkkkV_Operators-1.pptx
Python_Module_3_AFkkkkV_Operators-1.pptx
tissot723
 
Ad

Recently uploaded (20)

UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM & Mia eStudios
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM & Mia eStudios
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
Ad

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.
  翻译: