SlideShare a Scribd company logo
1 of 23
Presented By
Saurabh Upadhyay
1773513908
Operators
 An operator, in computer programming, is a symbol
that usually represents an action or process.
 It is a symbol that perform operation on one or more
operands.
 Operators required operands to perform their job.
3 4+
Operands
Operators
List Of Operators
i. Arithmetic Operator
ii. Relational Operator
iii. Logical Operator
iv. Bitwise Operator
v. Assignment Operator
vi. Identity Operator
vii. Membership Operator
1. Arithmetic Operator
 Arithmetic operators take numerical values as their
operands and return a single numerical value.
Operator Example Result
+ Addition 4+3 7
- Subtraction 4-3 1
* Multiplication 6*6 36
/ Division 3/2 1.5
% Modulus 7%3 1
** Exponent 3**2 9
// 3//2 1
Arithmetic Operator Example
10**-2
0.01
>>> -2**3
-8
>>> -2**2
-4
>>> 10//3
3
>>> 10.0//3.0
3.0
>>> -4%3
2
>>> -4%-3
-1
>>> x='abc'
>>> y='def'
>>> x+y
'abcdef’
>>> True+1
2
>>> 'ab'*3
'ababab'
2. Relational Operator
Oper
ator
Description Example
== If the values of two operands are equal, then the
condition becomes true.
(a ==
b) is not true.
!= If values of two operands are not equal, then
condition becomes true. a!=b is true
> If the value of left operand is greater than the value of
right operand, then condition becomes true.
(a > b) is true.
< If the value of left operand is less than the value of right
operand, then condition becomes true.
(a < b) is not true.
>= If the value of left operand is greater than or equal to
the value of right operand, then condition becomes true.
(a >=
b) is true.
<= If the value of left operand is less than or equal to the
value of right operand, then condition becomes true.
(a <=
b) is not
true.
Relational Operators Examples
 Relational operators always yield true or false as a result.
>>>5>4
True
>>>int(5>4)
1
 It is also used to compare string.
>>>’ac’==‘ac’
True
>>>ac==ac
error
 5>4<2 if any result value is false all result value is false.
>>>5>4>2
True
 If we use equality(==) operator with any type of operand
they never give error.
>>>5==‘5’
False
>>>’a’==97
False
>>>5=5.0
True
>>>’AB’==‘CD’
False
3. Logical Operator
Operator Expression Example
and a>b and a>c
When both operands are
True ,result will be True
or a>b or a>c
When both operands are
False result will be False
not not a>b
Invert the result
Expression 1 Expression 2 and or not(Exp 1)
T T T T F
T F F T F
F T F T T
F F F F T
 These operators return boolean value by validating
more than one expression.
 If the operands of logical operator are boolean value
then result is boolean otherwise if the operands of
logical operators are integer then result is integer.
>>>4>3 or 3<2
True
>>> 0 or False
False
 Logical operator must be written in lowercase only.
>>>5 and 4
4
 Empty string is always False non-empty string is True.
>>>3 and ‘ab’ #‘ab’ is string so ab=1(True)
‘ab’
Logical Operator Examples
>>>not ‘null’ #String is treated as True
False
>>>not ‘’
True
>>>’ram’ and ‘shyam’
‘ram’
>>>3 and x=4 #Assignment operator does not work their
error
>>>3 or 5/0
3
>>>3 and 5/0 #Evaluation is infinite
error
4. Bitwise Operator
 Bitwise operators work upon bits Ex:- 0 and 1
Operators Expression Example
& 5 & 6 4
| 5 | 6 7
~ ~5 -6
^ 5^6 3
>> 99>>2 24
<< 5<<3 40
I. &(AND):- 5 & 6
 Convert 5 and 6 into binary
5 - 101 1 & 1 = 1
& 1 & 0 = 0
6 - 110 0 & 1 = 0
4 - 100 0 & 0 = 0
5 - 101 1 | 1 = 1
| 1 | 0 = 0
6 - 110 0 | 1 = 0
7 - 111 0 | 0 = 0
II. |(OR):- 5 | 6
III. ~(Complement):-
>>>~12
-13
~x = -x -1
~12 = -12-1 = -13
Note: Our system does not store the negative
numbers , first we convert the number into 2’s
complement and then store.
12 = 00001100
1’s complement = 11110011
13 = 00001101
1’s complement = 11110010
2’s complement = 11110011
IV. ^(XOR):- 5^6
5 - 0101 1 ^ 1 = 0
^ 1 ^ 0 = 1
6 - 0110 0 ^ 1 = 1
3 - 0011 0 ^ 0 = 0
V. >>(right shift) :- 99>>2 VI. <<(left shift) :- 5<<3
99=1100011 5 = 101
1st time = 0110001 1st time = 1010
2nd time = 0011000 =24 2nd time = 10100
3rd time = 101000=40
5. Assignment Operator
Operator expression
= X=5
+=,-=,*=,/=,%= X+=5
//=,**= X**=2
&=,/=,^= X&=3
>>=,<<= X>>=2
(i) x=5
x*=6
x=x*6
=5*6
=30
(ii) x=5
x+=6
x=x+6
=5+6
=11
(iii) x=5
x/=6
x=x/6
=5/6
=0.833
(iv) x=5
x%=6
x=x%6
=5%6
=5
(v) x=5
x//=2
x=5//2
x=2
(vi) x=5
x**=2
x=5**2
x=25
6. Identity Operator
Operator Explanation
is Return True if both variables
are same object.
is not Return False if both variables
are same object.
-> Every variable in python is an object.
->Objects are dynamically created.
-> Objects do not have name but references.
x=5 x
y=5
y
5
1000
>>>X=5
>>>Y=5
>>>X==Y
True
>>>X is Y
True
>>>X=5
>>>Y=5.0
>>>X==Y
True
>>>X is Y
False
>>>X is not Y
True
6. Membership Operator
Operator Explanation
in Return True if a sequence with the
specified value is present in the object.
not in Return False if a sequence with the
specified value is present in the object.
>>>x=“abc”
>>>‘a’ in x
True
>>>x=“abc”
>>>’A’ not in x
True
>>>x=256
>>>’5’ in x
error
>>>’5 ‘ in x
False
>>> x=1,2,3,4
>>> 4 in x
True
Practice Session
>>>x=25*3/2-1
36.5
>>>x=5>4>3>2
True
>>>x=3
>>>x * = 3 + 4
21
>>>x = 3 and 4
4
>>>x = 2 or ‘Hello’
2
>>>x = ‘Hello’ + 3
error
>>>x = ‘ab’ * 4
abababab
>>>x = 3 == ‘Three’
False
Python operators

More Related Content

What's hot

Operators
OperatorsOperators
OperatorsKamran
 
Python operators
Python operatorsPython operators
Python operatorsnuripatidar
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operatorsdishti7
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++Neeru Mittal
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++bajiajugal
 
Expressions in c++
 Expressions in c++ Expressions in c++
Expressions in c++zeeshan turi
 
CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++Pranav Ghildiyal
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++Praveen M Jigajinni
 
Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++Online
 
Chapter 5 - Operators in C++
Chapter 5 - Operators in C++Chapter 5 - Operators in C++
Chapter 5 - Operators in C++Deepak Singh
 
C++ Expressions Notes
C++ Expressions NotesC++ Expressions Notes
C++ Expressions NotesProf Ansari
 

What's hot (17)

Operators
OperatorsOperators
Operators
 
Operators and Expressions
Operators and ExpressionsOperators and Expressions
Operators and Expressions
 
Operator.ppt
Operator.pptOperator.ppt
Operator.ppt
 
Python operators
Python operatorsPython operators
Python operators
 
Operators in C & C++ Language
Operators in C & C++ LanguageOperators in C & C++ Language
Operators in C & C++ Language
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
Operators in c++
Operators in c++Operators in c++
Operators in c++
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
 
Expressions in c++
 Expressions in c++ Expressions in c++
Expressions in c++
 
CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++
 
Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++
 
Chapter 5 - Operators in C++
Chapter 5 - Operators in C++Chapter 5 - Operators in C++
Chapter 5 - Operators in C++
 
C++ Expressions Notes
C++ Expressions NotesC++ Expressions Notes
C++ Expressions Notes
 
C – operators and expressions
C – operators and expressionsC – operators and expressions
C – operators and expressions
 

Similar to Python operators

Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statementsCtOlaf
 
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.pptxranaashutosh531pvt
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c languageTanmay Modi
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c languagetanmaymodi4
 
Few Operator used in c++
Few Operator used in c++Few Operator used in c++
Few Operator used in c++sunny khan
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)jahanullah
 
4. operators in c programming by digital wave
4. operators in  c programming by digital wave4. operators in  c programming by digital wave
4. operators in c programming by digital waveRahulSharma4566
 
Types of operators in C
Types of operators in CTypes of operators in C
Types of operators in CPrabhu Govind
 
03. Operators Expressions and statements
03. Operators Expressions and statements03. Operators Expressions and statements
03. Operators Expressions and statementsIntro C# Book
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3rohassanie
 

Similar to Python operators (20)

Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statements
 
Java - Operators
Java - OperatorsJava - Operators
Java - Operators
 
Java 2
Java 2Java 2
Java 2
 
What are operators?
What are operators? What are operators?
What are operators?
 
Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5
 
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
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c language
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Few Operator used in c++
Few Operator used in c++Few Operator used in c++
Few Operator used in c++
 
C operators ppt
C operators pptC operators ppt
C operators ppt
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
 
4. operators in c programming by digital wave
4. operators in  c programming by digital wave4. operators in  c programming by digital wave
4. operators in c programming by digital wave
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Types of operators in C
Types of operators in CTypes of operators in C
Types of operators in C
 
3306617
33066173306617
3306617
 
SPL 6 | Operators in C
SPL 6 | Operators in CSPL 6 | Operators in C
SPL 6 | Operators in C
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
 
Operators
OperatorsOperators
Operators
 
03. Operators Expressions and statements
03. Operators Expressions and statements03. Operators Expressions and statements
03. Operators Expressions and statements
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3
 

Recently uploaded

OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 

Recently uploaded (20)

OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 

Python operators

  • 2.
  • 3. Operators  An operator, in computer programming, is a symbol that usually represents an action or process.  It is a symbol that perform operation on one or more operands.  Operators required operands to perform their job. 3 4+ Operands Operators
  • 4. List Of Operators i. Arithmetic Operator ii. Relational Operator iii. Logical Operator iv. Bitwise Operator v. Assignment Operator vi. Identity Operator vii. Membership Operator
  • 5. 1. Arithmetic Operator  Arithmetic operators take numerical values as their operands and return a single numerical value. Operator Example Result + Addition 4+3 7 - Subtraction 4-3 1 * Multiplication 6*6 36 / Division 3/2 1.5 % Modulus 7%3 1 ** Exponent 3**2 9 // 3//2 1
  • 6. Arithmetic Operator Example 10**-2 0.01 >>> -2**3 -8 >>> -2**2 -4 >>> 10//3 3 >>> 10.0//3.0 3.0 >>> -4%3 2 >>> -4%-3 -1 >>> x='abc' >>> y='def' >>> x+y 'abcdef’ >>> True+1 2 >>> 'ab'*3 'ababab'
  • 7. 2. Relational Operator Oper ator Description Example == If the values of two operands are equal, then the condition becomes true. (a == b) is not true. != If values of two operands are not equal, then condition becomes true. a!=b is true > If the value of left operand is greater than the value of right operand, then condition becomes true. (a > b) is true. < If the value of left operand is less than the value of right operand, then condition becomes true. (a < b) is not true. >= If the value of left operand is greater than or equal to the value of right operand, then condition becomes true. (a >= b) is true. <= If the value of left operand is less than or equal to the value of right operand, then condition becomes true. (a <= b) is not true.
  • 8. Relational Operators Examples  Relational operators always yield true or false as a result. >>>5>4 True >>>int(5>4) 1  It is also used to compare string. >>>’ac’==‘ac’ True >>>ac==ac error
  • 9.  5>4<2 if any result value is false all result value is false. >>>5>4>2 True  If we use equality(==) operator with any type of operand they never give error. >>>5==‘5’ False >>>’a’==97 False >>>5=5.0 True >>>’AB’==‘CD’ False
  • 10. 3. Logical Operator Operator Expression Example and a>b and a>c When both operands are True ,result will be True or a>b or a>c When both operands are False result will be False not not a>b Invert the result Expression 1 Expression 2 and or not(Exp 1) T T T T F T F F T F F T F T T F F F F T
  • 11.  These operators return boolean value by validating more than one expression.  If the operands of logical operator are boolean value then result is boolean otherwise if the operands of logical operators are integer then result is integer. >>>4>3 or 3<2 True >>> 0 or False False  Logical operator must be written in lowercase only. >>>5 and 4 4  Empty string is always False non-empty string is True. >>>3 and ‘ab’ #‘ab’ is string so ab=1(True) ‘ab’
  • 12. Logical Operator Examples >>>not ‘null’ #String is treated as True False >>>not ‘’ True >>>’ram’ and ‘shyam’ ‘ram’ >>>3 and x=4 #Assignment operator does not work their error >>>3 or 5/0 3 >>>3 and 5/0 #Evaluation is infinite error
  • 13. 4. Bitwise Operator  Bitwise operators work upon bits Ex:- 0 and 1 Operators Expression Example & 5 & 6 4 | 5 | 6 7 ~ ~5 -6 ^ 5^6 3 >> 99>>2 24 << 5<<3 40
  • 14. I. &(AND):- 5 & 6  Convert 5 and 6 into binary 5 - 101 1 & 1 = 1 & 1 & 0 = 0 6 - 110 0 & 1 = 0 4 - 100 0 & 0 = 0 5 - 101 1 | 1 = 1 | 1 | 0 = 0 6 - 110 0 | 1 = 0 7 - 111 0 | 0 = 0 II. |(OR):- 5 | 6
  • 15. III. ~(Complement):- >>>~12 -13 ~x = -x -1 ~12 = -12-1 = -13 Note: Our system does not store the negative numbers , first we convert the number into 2’s complement and then store. 12 = 00001100 1’s complement = 11110011 13 = 00001101 1’s complement = 11110010 2’s complement = 11110011
  • 16. IV. ^(XOR):- 5^6 5 - 0101 1 ^ 1 = 0 ^ 1 ^ 0 = 1 6 - 0110 0 ^ 1 = 1 3 - 0011 0 ^ 0 = 0 V. >>(right shift) :- 99>>2 VI. <<(left shift) :- 5<<3 99=1100011 5 = 101 1st time = 0110001 1st time = 1010 2nd time = 0011000 =24 2nd time = 10100 3rd time = 101000=40
  • 17. 5. Assignment Operator Operator expression = X=5 +=,-=,*=,/=,%= X+=5 //=,**= X**=2 &=,/=,^= X&=3 >>=,<<= X>>=2
  • 18. (i) x=5 x*=6 x=x*6 =5*6 =30 (ii) x=5 x+=6 x=x+6 =5+6 =11 (iii) x=5 x/=6 x=x/6 =5/6 =0.833 (iv) x=5 x%=6 x=x%6 =5%6 =5 (v) x=5 x//=2 x=5//2 x=2 (vi) x=5 x**=2 x=5**2 x=25
  • 19. 6. Identity Operator Operator Explanation is Return True if both variables are same object. is not Return False if both variables are same object. -> Every variable in python is an object. ->Objects are dynamically created. -> Objects do not have name but references.
  • 20. x=5 x y=5 y 5 1000 >>>X=5 >>>Y=5 >>>X==Y True >>>X is Y True >>>X=5 >>>Y=5.0 >>>X==Y True >>>X is Y False >>>X is not Y True
  • 21. 6. Membership Operator Operator Explanation in Return True if a sequence with the specified value is present in the object. not in Return False if a sequence with the specified value is present in the object. >>>x=“abc” >>>‘a’ in x True >>>x=“abc” >>>’A’ not in x True >>>x=256 >>>’5’ in x error >>>’5 ‘ in x False >>> x=1,2,3,4 >>> 4 in x True
  • 22. Practice Session >>>x=25*3/2-1 36.5 >>>x=5>4>3>2 True >>>x=3 >>>x * = 3 + 4 21 >>>x = 3 and 4 4 >>>x = 2 or ‘Hello’ 2 >>>x = ‘Hello’ + 3 error >>>x = ‘ab’ * 4 abababab >>>x = 3 == ‘Three’ False