SlideShare a Scribd company logo
PYTHON
OPERATORS
PRESENTED BY:ZAINAB NIAZ(7614)
AIMAN ELAHI (7612)
BSCS-_8th
PYTHON OPERATORS
Operators Symbols
“Operators are used to perform operations on variables and values”
python divides the operators in the following groups:
1. ARITHMETIC OPERATORS.
2. ASSIGNMENT OPERATORS.
3. COMPARISON OPERATORS.
4. LOGICAL OPERATORS.
5. IDENTITY OPERATORS.
6. MEMBERSHIP OPERATORS.
7. BITWISE OPERATORS.
1. PYTHON ARITHMETIC OPERATORS
“Arithmetic operators are used with numeric values to perform common
mathematical operations”
ADDITION(+)
EXAMPLE
X + Y
X = 5
Y = 3
PRINT(X + Y)
SUBTRACTION(-)
EXAMPLE
X – Y
X = 5
Y = 3
PRINT(X - Y)
MULTIPLICATION(*)
EXAMPLE
X * Y
X = 5
Y = 3
PRINT(X * Y)
…
DIVISION(/)
EXAMPLE
X / Y
X = 12
Y = 3
PRINT(X / Y)
MODULUS(%)
EXAMPLE
X % Y
X = 5
Y = 2
PRINT(X % Y)
…
EXPONENTIATION(**)
EXAMPLE
X ** Y
X = 2
Y = 5
PRINT(X ** Y)
#SAME AS 2*2*2*2*2
FLOOR DIVISION(//)
EXAMPLE
X // Y
X = 15
Y = 2
PRINT(X // Y)
#THE FLOOR DIVISION // ROUNDS THE RESULT DOWN TO
THE NEAREST WHOLE NUMBER
2. PYTHON ASSIGNMENT OPERATORS
Assignment operators are used to assign values to variables:
(ASSIGNS TO) (=) x=5
+=(ASSIGNMENT AFTER ADDITION)
EXAMPLE
X += 3
SAME AS: X = X + 3
X = 5
X += 3
PRINT(X)
-=(ASSIGNMENT AFTER SUBTRACTION)
EXAMPLE
X -= 3
SAME AS: X = X – 3
X = 5
X -= 3
PRINT(X)
*= (ASSIGNMENT AFTER MULTIPLICATION)
EXAMPLE
X *= 3
SAME AS: X = X * 3
X = 5
X *= 3
PRINT(X)
…
/=(ASSIGNMENT AFTER DIVISION)
EXAMPLE
X /= 3
SAME AS: X = X / 3
X = 5
X /= 3
PRINT(X)
%= (ASSIGNMENT AFTER MODULUS)
EXAMPLE
X %= 3
SAME AS: X = X % 3
X = 5
X%=3
PRINT(X)
…
**= (ASSIGNMENT AFTER EXPONENT)
EXAMPLE
X **= 3
SAME AS: X = X ** 3
X = 5
X **= 3
PRINT(X)
//= (ASSIGNMENT AFTER FLOOR DIVISION)
EXAMPLE
X //= 3
SAME AS: X = X // 3
X = 5
X//=3
PRINT(X)
3. PYTHON COMPARISON OPERATORS
“Comparison operators are used to comparing the value of the two operands and returns boolean
true or false accordingly”
EQUAL (==)
EXAMPLE
X == Y
X = 5
Y = 3
PRINT(X == Y)
# RETURNS FALSE BECAUSE 5 IS NOT EQUAL
TO 3
NOT EQUAL (!=)
EXAMPLE
X != Y
X = 5
Y = 3
PRINT(X != Y)
# RETURNS TRUE BECAUSE 5 IS NOT EQUAL
TO 3
…
GREATER THAN (>)
EXAMPLE
X > Y
X = 5
Y = 3
PRINT(X > Y)
# RETURNS TRUE BECAUSE 5 IS GREATER
THAN 3
LESS THAN (<)
EXAMPLE
X < Y
X = 5
Y = 3
PRINT(X < Y)
# RETURNS FALSE BECAUSE 5 IS NOT LESS
THAN 3
…
GREATER THAN OR EQUAL TO
(>=)
EXAMPLE
X >= Y
X = 5
Y = 3
PRINT(X >= Y)
# RETURNS TRUE BECAUSE FIVE IS GREATER
THAN 3
LESS THAN OR EQUAL TO
(<=)
EXAMPLE
X <= Y
X = 5
Y = 3
PRINT(X <= Y)
# RETURNS FALSE BECAUSE 5 IS NEITHER
LESS THAN 3
4. PYTHON LOGICAL OPERATORS
Logical operators are used to combine conditional statements
OR
The logical operators are used primarily in the expression evaluation to make a decision
AND (LOGICAL AND)
Returns true if both statements are true
EXAMPLE
X < 5 AND X < 10
x = 5
print(x > 3 and x < 10)
# returns True because 5 is greater than 3 AND 5 is less than 10
…
OR (LOGICAL OR)
Returns true if one of the statements is true
EXAMPLE
X < 5 OR X < 4
X = 5
PRINT(X > 3 OR X < 4)
# RETURNS TRUE BECAUSE ONE OF THE CONDITIONS ARE TRUE (5 IS GREATER THAN 3,
BUT 5 IS NOT LESS THAN 4)
…
NOT (LOGICAL NOT)
Reverse the result, returns false if the result is true
EXAMPLE
NOT(X < 5 AND X < 10)
X = 5
PRINT(NOT(X > 3 AND X < 10))
# RETURNS FALSE BECAUSE NOT IS USED TO REVERSE THE RESULT
PYTHON OPERATORS
• IDENTITY OPERATORS
• MEMBERSHIP OPERATORS
• BITWISE OPERATORS
5. PYTHON IDENTITY OPERATORS
• Identity operators are used to compare the objects, not if they are equal, but if
they are actually the same object, with the same memory location
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
EXAMPLE:
6. PYTHON MEMBERSHIP OPERATORS
• MEMBERSHIP OPERATORS ARE USED TO TEST IF A SEQUENCE IS
PRESENTED IN AN OBJECT:
Operator Description Example
in
Returns True if a sequence
with the specified value is
present in the object
x in y
not in
Returns True if a sequence
with the specified value is
not present in the object
x not in y
EXAMPLE:
7. PYTHON BITWISE OPERATORS
• BITWISE OPERATORS ARE USED TO COMPARE (BINARY) NUMBERS
Operator Name Description
& AND Sets each bit to 1 if both bits are 1
| OR Sets each bit to 1 if one of two bits is 1
^ XOR Sets each bit to 1 if only one of two bits is 1
~ NOT Inverts all the bits
<< Zero fill left
shift
Shift left by pushing zeros in from the right and let the leftmost bits
fall off
>> Signed
right shift
Shift right by pushing copies of the leftmost bit in from the left, and
let the rightmost bits fall off
THANKYOU

More Related Content

What's hot

C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
guest58c84c
 
How to use vlookup in MS Excel
How to use vlookup in MS ExcelHow to use vlookup in MS Excel
How to use vlookup in MS Excel
Jaspal Singh
 
Operators in python
Operators in pythonOperators in python
Operators in python
Prabhakaran V M
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
dishti7
 
Python : basic operators
Python : basic operatorsPython : basic operators
Python : basic operators
S.M. Salaquzzaman
 
Vlookup - an introduction
Vlookup - an introductionVlookup - an introduction
Vlookup - an introduction
vvmenon22
 
Supplement 13.1 blitzer tm4th
Supplement 13.1 blitzer tm4thSupplement 13.1 blitzer tm4th
Supplement 13.1 blitzer tm4th
Gideon Weinstein
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
Jordan Delacruz
 
Operator of C language
Operator of C languageOperator of C language
Operator of C language
Kritika Chauhan
 
How to use Hlookup find an exact match
How to use Hlookup find an exact match How to use Hlookup find an exact match
How to use Hlookup find an exact match
Excel Advise
 
Operators in java
Operators in javaOperators in java
Operators in java
yugandhar vadlamudi
 
itft-Operators in java
itft-Operators in javaitft-Operators in java
itft-Operators in java
Atul Sehdev
 
C OPERATOR
C OPERATORC OPERATOR
C OPERATOR
rricky98
 
VLOOKUP Function - Marelen Talavera - Vivacious Analytic
VLOOKUP Function - Marelen Talavera - Vivacious AnalyticVLOOKUP Function - Marelen Talavera - Vivacious Analytic
VLOOKUP Function - Marelen Talavera - Vivacious Analytic
Maria Elena Acdol-Talavera
 
Operators
OperatorsOperators
Operators
Kamran
 
Operators
OperatorsOperators
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programming
Manoj Tyagi
 
Operators and Expressions
Operators and ExpressionsOperators and Expressions
Operators and Expressions
Munazza-Mah-Jabeen
 
Operators in Java
Operators in JavaOperators in Java
Operators in Java
Rhythm Suiwal
 

What's hot (19)

C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
 
How to use vlookup in MS Excel
How to use vlookup in MS ExcelHow to use vlookup in MS Excel
How to use vlookup in MS Excel
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
 
Python : basic operators
Python : basic operatorsPython : basic operators
Python : basic operators
 
Vlookup - an introduction
Vlookup - an introductionVlookup - an introduction
Vlookup - an introduction
 
Supplement 13.1 blitzer tm4th
Supplement 13.1 blitzer tm4thSupplement 13.1 blitzer tm4th
Supplement 13.1 blitzer tm4th
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
 
Operator of C language
Operator of C languageOperator of C language
Operator of C language
 
How to use Hlookup find an exact match
How to use Hlookup find an exact match How to use Hlookup find an exact match
How to use Hlookup find an exact match
 
Operators in java
Operators in javaOperators in java
Operators in java
 
itft-Operators in java
itft-Operators in javaitft-Operators in java
itft-Operators in java
 
C OPERATOR
C OPERATORC OPERATOR
C OPERATOR
 
VLOOKUP Function - Marelen Talavera - Vivacious Analytic
VLOOKUP Function - Marelen Talavera - Vivacious AnalyticVLOOKUP Function - Marelen Talavera - Vivacious Analytic
VLOOKUP Function - Marelen Talavera - Vivacious Analytic
 
Operators
OperatorsOperators
Operators
 
Operators
OperatorsOperators
Operators
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programming
 
Operators and Expressions
Operators and ExpressionsOperators and Expressions
Operators and Expressions
 
Operators in Java
Operators in JavaOperators in Java
Operators in Java
 

Similar to python operators.pptx

OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2
vikram mahendra
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
savitamhaske
 
lecture5 bca 1 year.pptx
lecture5 bca 1 year.pptxlecture5 bca 1 year.pptx
lecture5 bca 1 year.pptx
classall
 
C PRESENTATION.pptx
C PRESENTATION.pptxC PRESENTATION.pptx
C PRESENTATION.pptx
VAIBHAV175947
 
Introduction to Python
Introduction to Python  Introduction to Python
Introduction to Python
Mohammed Sikander
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
Ankita Shirke
 
1_Python Basics.pdf
1_Python Basics.pdf1_Python Basics.pdf
1_Python Basics.pdf
MaheshGour5
 
Python second ppt
Python second pptPython second ppt
Python second ppt
RaginiJain21
 
This slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptxThis slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptx
ranaashutosh531pvt
 
Python basic operators
Python   basic operatorsPython   basic operators
Python basic operators
Learnbay Datascience
 
Python
PythonPython
Rational-Function-W3-4.pptx
Rational-Function-W3-4.pptxRational-Function-W3-4.pptx
Rational-Function-W3-4.pptx
MYRABACSAFRA2
 
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
 
Python
PythonPython
Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5
Mohd Harris Ahmad Jaal
 
Java script questions
Java script questionsJava script questions
Java script questions
Srikanth
 
Operators
OperatorsOperators
Operators
loidasacueza
 
Php
PhpPhp
Python_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptxPython_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptx
SahajShrimal1
 

Similar to python operators.pptx (20)

OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
 
lecture5 bca 1 year.pptx
lecture5 bca 1 year.pptxlecture5 bca 1 year.pptx
lecture5 bca 1 year.pptx
 
C PRESENTATION.pptx
C PRESENTATION.pptxC PRESENTATION.pptx
C PRESENTATION.pptx
 
Introduction to Python
Introduction to Python  Introduction to Python
Introduction to Python
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
 
1_Python Basics.pdf
1_Python Basics.pdf1_Python Basics.pdf
1_Python Basics.pdf
 
Python second ppt
Python second pptPython second ppt
Python second ppt
 
This slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptxThis slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptx
 
Python basic operators
Python   basic operatorsPython   basic operators
Python basic operators
 
Python
PythonPython
Python
 
Rational-Function-W3-4.pptx
Rational-Function-W3-4.pptxRational-Function-W3-4.pptx
Rational-Function-W3-4.pptx
 
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
 
Python
PythonPython
Python
 
Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5
 
Java script questions
Java script questionsJava script questions
Java script questions
 
Operators
OperatorsOperators
Operators
 
Php
PhpPhp
Php
 
Python_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptxPython_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptx
 

Recently uploaded

KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
GohKiangHock
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
Marcin Chrost
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
mz5nrf0n
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
TaghreedAltamimi
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
Rakesh Kumar R
 
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
ssuserad3af4
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 

Recently uploaded (20)

KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
 
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 

python operators.pptx

  • 2. PYTHON OPERATORS Operators Symbols “Operators are used to perform operations on variables and values” python divides the operators in the following groups: 1. ARITHMETIC OPERATORS. 2. ASSIGNMENT OPERATORS. 3. COMPARISON OPERATORS. 4. LOGICAL OPERATORS. 5. IDENTITY OPERATORS. 6. MEMBERSHIP OPERATORS. 7. BITWISE OPERATORS.
  • 3. 1. PYTHON ARITHMETIC OPERATORS “Arithmetic operators are used with numeric values to perform common mathematical operations” ADDITION(+) EXAMPLE X + Y X = 5 Y = 3 PRINT(X + Y) SUBTRACTION(-) EXAMPLE X – Y X = 5 Y = 3 PRINT(X - Y) MULTIPLICATION(*) EXAMPLE X * Y X = 5 Y = 3 PRINT(X * Y)
  • 4. … DIVISION(/) EXAMPLE X / Y X = 12 Y = 3 PRINT(X / Y) MODULUS(%) EXAMPLE X % Y X = 5 Y = 2 PRINT(X % Y)
  • 5. … EXPONENTIATION(**) EXAMPLE X ** Y X = 2 Y = 5 PRINT(X ** Y) #SAME AS 2*2*2*2*2 FLOOR DIVISION(//) EXAMPLE X // Y X = 15 Y = 2 PRINT(X // Y) #THE FLOOR DIVISION // ROUNDS THE RESULT DOWN TO THE NEAREST WHOLE NUMBER
  • 6. 2. PYTHON ASSIGNMENT OPERATORS Assignment operators are used to assign values to variables: (ASSIGNS TO) (=) x=5 +=(ASSIGNMENT AFTER ADDITION) EXAMPLE X += 3 SAME AS: X = X + 3 X = 5 X += 3 PRINT(X) -=(ASSIGNMENT AFTER SUBTRACTION) EXAMPLE X -= 3 SAME AS: X = X – 3 X = 5 X -= 3 PRINT(X) *= (ASSIGNMENT AFTER MULTIPLICATION) EXAMPLE X *= 3 SAME AS: X = X * 3 X = 5 X *= 3 PRINT(X)
  • 7. … /=(ASSIGNMENT AFTER DIVISION) EXAMPLE X /= 3 SAME AS: X = X / 3 X = 5 X /= 3 PRINT(X) %= (ASSIGNMENT AFTER MODULUS) EXAMPLE X %= 3 SAME AS: X = X % 3 X = 5 X%=3 PRINT(X)
  • 8. … **= (ASSIGNMENT AFTER EXPONENT) EXAMPLE X **= 3 SAME AS: X = X ** 3 X = 5 X **= 3 PRINT(X) //= (ASSIGNMENT AFTER FLOOR DIVISION) EXAMPLE X //= 3 SAME AS: X = X // 3 X = 5 X//=3 PRINT(X)
  • 9. 3. PYTHON COMPARISON OPERATORS “Comparison operators are used to comparing the value of the two operands and returns boolean true or false accordingly” EQUAL (==) EXAMPLE X == Y X = 5 Y = 3 PRINT(X == Y) # RETURNS FALSE BECAUSE 5 IS NOT EQUAL TO 3 NOT EQUAL (!=) EXAMPLE X != Y X = 5 Y = 3 PRINT(X != Y) # RETURNS TRUE BECAUSE 5 IS NOT EQUAL TO 3
  • 10. … GREATER THAN (>) EXAMPLE X > Y X = 5 Y = 3 PRINT(X > Y) # RETURNS TRUE BECAUSE 5 IS GREATER THAN 3 LESS THAN (<) EXAMPLE X < Y X = 5 Y = 3 PRINT(X < Y) # RETURNS FALSE BECAUSE 5 IS NOT LESS THAN 3
  • 11. … GREATER THAN OR EQUAL TO (>=) EXAMPLE X >= Y X = 5 Y = 3 PRINT(X >= Y) # RETURNS TRUE BECAUSE FIVE IS GREATER THAN 3 LESS THAN OR EQUAL TO (<=) EXAMPLE X <= Y X = 5 Y = 3 PRINT(X <= Y) # RETURNS FALSE BECAUSE 5 IS NEITHER LESS THAN 3
  • 12. 4. PYTHON LOGICAL OPERATORS Logical operators are used to combine conditional statements OR The logical operators are used primarily in the expression evaluation to make a decision AND (LOGICAL AND) Returns true if both statements are true EXAMPLE X < 5 AND X < 10 x = 5 print(x > 3 and x < 10) # returns True because 5 is greater than 3 AND 5 is less than 10
  • 13. … OR (LOGICAL OR) Returns true if one of the statements is true EXAMPLE X < 5 OR X < 4 X = 5 PRINT(X > 3 OR X < 4) # RETURNS TRUE BECAUSE ONE OF THE CONDITIONS ARE TRUE (5 IS GREATER THAN 3, BUT 5 IS NOT LESS THAN 4)
  • 14. … NOT (LOGICAL NOT) Reverse the result, returns false if the result is true EXAMPLE NOT(X < 5 AND X < 10) X = 5 PRINT(NOT(X > 3 AND X < 10)) # RETURNS FALSE BECAUSE NOT IS USED TO REVERSE THE RESULT
  • 15. PYTHON OPERATORS • IDENTITY OPERATORS • MEMBERSHIP OPERATORS • BITWISE OPERATORS
  • 16. 5. PYTHON IDENTITY OPERATORS • Identity operators are used to compare the objects, not if they are equal, but if they are actually the same object, with the same memory location 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
  • 18. 6. PYTHON MEMBERSHIP OPERATORS • MEMBERSHIP OPERATORS ARE USED TO TEST IF A SEQUENCE IS PRESENTED IN AN OBJECT: Operator Description Example in Returns True if a sequence with the specified value is present in the object x in y not in Returns True if a sequence with the specified value is not present in the object x not in y
  • 20. 7. PYTHON BITWISE OPERATORS • BITWISE OPERATORS ARE USED TO COMPARE (BINARY) NUMBERS Operator Name Description & AND Sets each bit to 1 if both bits are 1 | OR Sets each bit to 1 if one of two bits is 1 ^ XOR Sets each bit to 1 if only one of two bits is 1 ~ NOT Inverts all the bits << Zero fill left shift Shift left by pushing zeros in from the right and let the leftmost bits fall off >> Signed right shift Shift right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall off
  • 21.
  • 22.
  • 23.