SlideShare a Scribd company logo
V.M.Prabhakaran,
Department Of Cse,
KIT- Coimbatore
Problem Solving and Python Programming 1
OPERATORS
Problem Solving and Python Programming 2
• An operator is a symbol that represents an
operations that may be performed on one or
more operands.
• An operand is a value that a given operator is
applied to.
• Example: 4+(3*k)
+, * are operator and 4,3,k are operands
Different forms of operator
• Unary Operator:
– Unary arithmetic operators perform mathematical operations on
one operand only. The „+‟ and „-„‟ are two unary operators.
– Example:
>>> x = -5 #Negates the value of X
>>> x
-5
• Binary operator:
– A Binary operator operates on two operands
– Example:
>>> 3 + 10
>>>13
>>> 10 – 7
>>> 3
Problem Solving and Python Programming 3
Types of Operators
1. Arithmetic operator
2. Relational operator
3. Logical operator
4. Bitwise operator
5. Assignment operator
6. Special operator
Problem Solving and Python Programming 4
1. Arithmetic operator
• Arithmetic operators are basic mathematical
operations.
Problem Solving and Python Programming 5
Operator Meaning Example Result
+ Addition C=12+1 C=13
- Subtraction C=12-1 C=11
* Multiplication C=12*1 C=12
/ Division C=12/1 C=12
// Floor division C=12//10 1
% Modulus C=12%10 C=2
** Exponentiation C=10**2 C=100
Example of Arithmetic Operator
print("Arithmetic Operator")
a=10
b=5
print("Addition:",a+b)
print("Subtraction:",a-b)
print("Multiplication:",a*b)
print("Division:",a/b)
print("Floor Division:",a//b)
print("Modulus:",a%b)
print("Exponent",a**b)
Problem Solving and Python Programming 6
Output:
2. Relational operator
• Relational operators are also called as Comparison
operators
• It is used to compare values.
• It either returns True or False according to condition.
Problem Solving and Python Programming 7
Operator Meaning Example Result
> Greater than 5>6 False
< Less than 5<6 True
== Equal to 5==6 False
!= Not equal to 5!=6 True
>= Greater than or equal to 5>=6 False
<= Less than or equal to 5<=6 True
Example of Relational Operator
print("Relational Operator")
a=10
b=5
print(a>b)
print(a<b)
print(a==b)
print(a!=b)
print(a>=b)
print(a<=b)
Problem Solving and Python Programming 8
Output:
3. Logical operator
Problem Solving and Python Programming 9
• Logical operator are typically used with
Boolean(logical) values.
• They allow a program to make a decision
based on multiple condition.
Operator Meaning Example Result
and True if both the
operands are true
10<5 and 10<20 False
or True if either of the
operands is true
10<5 or 10<20 True
not True if operands is
false ( complements
the operand)
not (10<20) False
Example of Logical Operator
print("Logical Operator")
print(10<5 and 10<20)
print(10<5 or 10<20)
print(not(10<20))
Problem Solving and Python Programming 10
Logical Operator
False
True
False
Output:
4. Bitwise operator
• Bitwise operators act on operands as if they are
string of binary digits.
• It operates bit by bit.
Problem Solving and Python Programming 11
Operator Meaning Example
& Bitwise AND a & b
| Bitwise OR a | b
~ Bitwise NOT a ~ b
^ Bitwise XOR a ^ b
>> Bitwise right shift a >> 2
<< Bitwise left shift a << 2
5. Assignment operator
• Assignment operators are used to assign values
to variables.
Problem Solving and Python Programming 12
Operator Meaning Example
= Assign a value a=5
+= Adds and assign the result to the variable a+=1 (a=a+1)
-= Subtracts and assign the result to the variable a-=1 (a=a-1)
*= Multiplies and assign the result to the variable a*=5 (a=a*5)
/= Division and assign the result to the variable a/= (a=a/5)
//= Floor division and assign the result to the variable a//=5(a=a//5)
%= Find modulus and assign the result to the variable a%=5 (a=a%5)
**= Find Exponentiation and assign the result to the
variable
a**=5 (a=a**5)
Problem Solving and Python Programming 13
Operator Meaning Example
&= Find Bitwise AND and assign the result to the variable a&=5(a=a&5)
|= Find Bitwise OR and assign the result to the variable a|=5(a=a|5)
^= Find Bitwise XOR and assign the result to the variable a^=5(a=a^5)
>>= Find Bitwise right shift and assign the result to the
variable
a>>=5 (a=a>>5)
<<= Find Bitwise left shift and assign the result to the
variable
a<<=5 (a=a<<5)
6. Special operator
• Python offers some special operators like
identity operator and the membership operator.
• Identity Operator:
– is and is not are the identity operator
Problem Solving and Python Programming 14
Operator Meaning Example
is True if the operands
are identical
a is true
is not True if the operands
are not identical
a is not true
Example of Identity Operator
a1=5
b1=5
a2="Hello"
b2="Hello"
a3=[1,2,3]
b3=[1,2,3]
print(a1 is not b1)
print(a2 is b2)
print(a2 is b3)
Problem Solving and Python Programming 15
Output:
False
True
False
• Membership Operators:
– in and not in are the membership operators.
Problem Solving and Python Programming 16
Operator Meaning Example
in True if value/
variable is found in
the sequence
5 in a
not in True if value/
variable is not
found in the
sequence
5 not in a
Example of Membership Operator
a="Hello world"
b={1,"a","b",2}
print("H" in a)
print("hello" in a )
print(1 in b)
print("b" in b)
Print(“c” not in b)
Problem Solving and Python Programming 17
Output:
True
False
True
True
True

More Related Content

What's hot

Python Modules
Python ModulesPython Modules
Python Modules
Nitin Reddy Katkam
 
Operators in python
Operators in pythonOperators in python
Operators in python
eShikshak
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
RaginiJain21
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
eShikshak
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
Mohammed Sikander
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
Sujith Kumar
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
Srinivas Narasegouda
 
Python libraries
Python librariesPython libraries
Python libraries
Prof. Dr. K. Adisesha
 
Variables in python
Variables in pythonVariables in python
Variables in python
Jaya Kumari
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
Megha V
 
Variables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaVariables & Data Types In Python | Edureka
Variables & Data Types In Python | Edureka
Edureka!
 
Python Programming ppt
Python Programming pptPython Programming ppt
Python Programming ppt
ismailmrribi
 
Python final ppt
Python final pptPython final ppt
Python final ppt
Ripal Ranpara
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
Dr.YNM
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
Anusuya123
 
Python basics
Python basicsPython basics
Python basics
RANAALIMAJEEDRAJPUT
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
narmadhakin
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 
Chapter 07 inheritance
Chapter 07 inheritanceChapter 07 inheritance
Chapter 07 inheritance
Praveen M Jigajinni
 
Python by Rj
Python by RjPython by Rj

What's hot (20)

Python Modules
Python ModulesPython Modules
Python Modules
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Python libraries
Python librariesPython libraries
Python libraries
 
Variables in python
Variables in pythonVariables in python
Variables in python
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
Variables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaVariables & Data Types In Python | Edureka
Variables & Data Types In Python | Edureka
 
Python Programming ppt
Python Programming pptPython Programming ppt
Python Programming ppt
 
Python final ppt
Python final pptPython final ppt
Python final ppt
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
 
Python basics
Python basicsPython basics
Python basics
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
Chapter 07 inheritance
Chapter 07 inheritanceChapter 07 inheritance
Chapter 07 inheritance
 
Python by Rj
Python by RjPython by Rj
Python by Rj
 

Similar to Operators in python

Operators_in_Python_Simplified_languages
Operators_in_Python_Simplified_languagesOperators_in_Python_Simplified_languages
Operators_in_Python_Simplified_languages
AbhishekGupta692777
 
Operators in Python Arithmetic Operators
Operators in Python Arithmetic OperatorsOperators in Python Arithmetic Operators
Operators in Python Arithmetic Operators
ramireddyobulakondar
 
Operators
OperatorsOperators
Operators
Kamran
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)jahanullah
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
Neeru Mittal
 
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++
Praveen M Jigajinni
 
Lecture 05.pptx
Lecture 05.pptxLecture 05.pptx
Lecture 05.pptx
Mohammad Hassan
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statementsCtOlaf
 
Oop using JAVA
Oop using JAVAOop using JAVA
Oop using JAVA
umardanjumamaiwada
 
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp013 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01Abdul Samee
 
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp013 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01Abdul Samee
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++bajiajugal
 
Coper in C
Coper in CCoper in C
Coper in C
thirumalaikumar3
 
lecture4 pgdca.pptx
lecture4 pgdca.pptxlecture4 pgdca.pptx
lecture4 pgdca.pptx
classall
 
03. Operators Expressions and statements
03. Operators Expressions and statements03. Operators Expressions and statements
03. Operators Expressions and statements
Intro C# Book
 
03 Operators and expressions
03 Operators and expressions03 Operators and expressions
03 Operators and expressions
maznabili
 
03. operators and-expressions
03. operators and-expressions03. operators and-expressions
03. operators and-expressions
Stoian Kirov
 
C++ Programming Basics.pptx
C++ Programming Basics.pptxC++ Programming Basics.pptx
C++ Programming Basics.pptx
ZntalemAbebe
 

Similar to Operators in python (20)

Operators_in_Python_Simplified_languages
Operators_in_Python_Simplified_languagesOperators_in_Python_Simplified_languages
Operators_in_Python_Simplified_languages
 
Operators in Python Arithmetic Operators
Operators in Python Arithmetic OperatorsOperators in Python Arithmetic Operators
Operators in Python Arithmetic Operators
 
Operators
OperatorsOperators
Operators
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
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
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++
 
Lecture 05.pptx
Lecture 05.pptxLecture 05.pptx
Lecture 05.pptx
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statements
 
Oop using JAVA
Oop using JAVAOop using JAVA
Oop using JAVA
 
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp013 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01
 
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp013 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
 
Coper in C
Coper in CCoper in C
Coper in C
 
lecture4 pgdca.pptx
lecture4 pgdca.pptxlecture4 pgdca.pptx
lecture4 pgdca.pptx
 
03. Operators Expressions and statements
03. Operators Expressions and statements03. Operators Expressions and statements
03. Operators Expressions and statements
 
03 Operators and expressions
03 Operators and expressions03 Operators and expressions
03 Operators and expressions
 
03. operators and-expressions
03. operators and-expressions03. operators and-expressions
03. operators and-expressions
 
C++ Programming Basics.pptx
C++ Programming Basics.pptxC++ Programming Basics.pptx
C++ Programming Basics.pptx
 

More from Prabhakaran V M

Algorithmic problem solving
Algorithmic problem solvingAlgorithmic problem solving
Algorithmic problem solving
Prabhakaran V M
 
Open mp directives
Open mp directivesOpen mp directives
Open mp directives
Prabhakaran V M
 
Xml schema
Xml schemaXml schema
Xml schema
Prabhakaran V M
 
Html 5
Html 5Html 5
Introduction to Multi-core Architectures
Introduction to Multi-core ArchitecturesIntroduction to Multi-core Architectures
Introduction to Multi-core Architectures
Prabhakaran V M
 
Java threads
Java threadsJava threads
Java threads
Prabhakaran V M
 
Applets
AppletsApplets

More from Prabhakaran V M (7)

Algorithmic problem solving
Algorithmic problem solvingAlgorithmic problem solving
Algorithmic problem solving
 
Open mp directives
Open mp directivesOpen mp directives
Open mp directives
 
Xml schema
Xml schemaXml schema
Xml schema
 
Html 5
Html 5Html 5
Html 5
 
Introduction to Multi-core Architectures
Introduction to Multi-core ArchitecturesIntroduction to Multi-core Architectures
Introduction to Multi-core Architectures
 
Java threads
Java threadsJava threads
Java threads
 
Applets
AppletsApplets
Applets
 

Recently uploaded

How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
Peter Caitens
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
varshanayak241
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
NaapbooksPrivateLimi
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
ayushiqss
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 

Recently uploaded (20)

How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 

Operators in python

  • 1. V.M.Prabhakaran, Department Of Cse, KIT- Coimbatore Problem Solving and Python Programming 1
  • 2. OPERATORS Problem Solving and Python Programming 2 • An operator is a symbol that represents an operations that may be performed on one or more operands. • An operand is a value that a given operator is applied to. • Example: 4+(3*k) +, * are operator and 4,3,k are operands
  • 3. Different forms of operator • Unary Operator: – Unary arithmetic operators perform mathematical operations on one operand only. The „+‟ and „-„‟ are two unary operators. – Example: >>> x = -5 #Negates the value of X >>> x -5 • Binary operator: – A Binary operator operates on two operands – Example: >>> 3 + 10 >>>13 >>> 10 – 7 >>> 3 Problem Solving and Python Programming 3
  • 4. Types of Operators 1. Arithmetic operator 2. Relational operator 3. Logical operator 4. Bitwise operator 5. Assignment operator 6. Special operator Problem Solving and Python Programming 4
  • 5. 1. Arithmetic operator • Arithmetic operators are basic mathematical operations. Problem Solving and Python Programming 5 Operator Meaning Example Result + Addition C=12+1 C=13 - Subtraction C=12-1 C=11 * Multiplication C=12*1 C=12 / Division C=12/1 C=12 // Floor division C=12//10 1 % Modulus C=12%10 C=2 ** Exponentiation C=10**2 C=100
  • 6. Example of Arithmetic Operator print("Arithmetic Operator") a=10 b=5 print("Addition:",a+b) print("Subtraction:",a-b) print("Multiplication:",a*b) print("Division:",a/b) print("Floor Division:",a//b) print("Modulus:",a%b) print("Exponent",a**b) Problem Solving and Python Programming 6 Output:
  • 7. 2. Relational operator • Relational operators are also called as Comparison operators • It is used to compare values. • It either returns True or False according to condition. Problem Solving and Python Programming 7 Operator Meaning Example Result > Greater than 5>6 False < Less than 5<6 True == Equal to 5==6 False != Not equal to 5!=6 True >= Greater than or equal to 5>=6 False <= Less than or equal to 5<=6 True
  • 8. Example of Relational Operator print("Relational Operator") a=10 b=5 print(a>b) print(a<b) print(a==b) print(a!=b) print(a>=b) print(a<=b) Problem Solving and Python Programming 8 Output:
  • 9. 3. Logical operator Problem Solving and Python Programming 9 • Logical operator are typically used with Boolean(logical) values. • They allow a program to make a decision based on multiple condition. Operator Meaning Example Result and True if both the operands are true 10<5 and 10<20 False or True if either of the operands is true 10<5 or 10<20 True not True if operands is false ( complements the operand) not (10<20) False
  • 10. Example of Logical Operator print("Logical Operator") print(10<5 and 10<20) print(10<5 or 10<20) print(not(10<20)) Problem Solving and Python Programming 10 Logical Operator False True False Output:
  • 11. 4. Bitwise operator • Bitwise operators act on operands as if they are string of binary digits. • It operates bit by bit. Problem Solving and Python Programming 11 Operator Meaning Example & Bitwise AND a & b | Bitwise OR a | b ~ Bitwise NOT a ~ b ^ Bitwise XOR a ^ b >> Bitwise right shift a >> 2 << Bitwise left shift a << 2
  • 12. 5. Assignment operator • Assignment operators are used to assign values to variables. Problem Solving and Python Programming 12 Operator Meaning Example = Assign a value a=5 += Adds and assign the result to the variable a+=1 (a=a+1) -= Subtracts and assign the result to the variable a-=1 (a=a-1) *= Multiplies and assign the result to the variable a*=5 (a=a*5) /= Division and assign the result to the variable a/= (a=a/5) //= Floor division and assign the result to the variable a//=5(a=a//5) %= Find modulus and assign the result to the variable a%=5 (a=a%5) **= Find Exponentiation and assign the result to the variable a**=5 (a=a**5)
  • 13. Problem Solving and Python Programming 13 Operator Meaning Example &= Find Bitwise AND and assign the result to the variable a&=5(a=a&5) |= Find Bitwise OR and assign the result to the variable a|=5(a=a|5) ^= Find Bitwise XOR and assign the result to the variable a^=5(a=a^5) >>= Find Bitwise right shift and assign the result to the variable a>>=5 (a=a>>5) <<= Find Bitwise left shift and assign the result to the variable a<<=5 (a=a<<5)
  • 14. 6. Special operator • Python offers some special operators like identity operator and the membership operator. • Identity Operator: – is and is not are the identity operator Problem Solving and Python Programming 14 Operator Meaning Example is True if the operands are identical a is true is not True if the operands are not identical a is not true
  • 15. Example of Identity Operator a1=5 b1=5 a2="Hello" b2="Hello" a3=[1,2,3] b3=[1,2,3] print(a1 is not b1) print(a2 is b2) print(a2 is b3) Problem Solving and Python Programming 15 Output: False True False
  • 16. • Membership Operators: – in and not in are the membership operators. Problem Solving and Python Programming 16 Operator Meaning Example in True if value/ variable is found in the sequence 5 in a not in True if value/ variable is not found in the sequence 5 not in a
  • 17. Example of Membership Operator a="Hello world" b={1,"a","b",2} print("H" in a) print("hello" in a ) print(1 in b) print("b" in b) Print(“c” not in b) Problem Solving and Python Programming 17 Output: True False True True True