SlideShare a Scribd company logo
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
Operators
Kamran
 
Operators and Expressions
Operators and ExpressionsOperators and Expressions
Operators and Expressions
Munazza-Mah-Jabeen
 
Operator.ppt
Operator.pptOperator.ppt
Operator.ppt
Darshan Patel
 
Python operators
Python operatorsPython operators
Python operators
nuripatidar
 
Operators in C & C++ Language
Operators in C & C++ LanguageOperators in C & C++ Language
Operators in C & C++ Language
PreSolutions Softwares
 
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
 
Operators in c++
Operators in c++Operators in c++
Operators in c++
ABHIJITPATRA23
 
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 Notes
Prof 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
 
What are operators?
What are operators? What are operators?
What are operators?
AnuragSrivastava272
 
power point presentation on topic in C++ called "OPERATORS"
power point presentation on topic in C++ called "OPERATORS"power point presentation on topic in C++ called "OPERATORS"
power point presentation on topic in C++ called "OPERATORS"
sj9399037128
 
Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5
Mohd Harris Ahmad Jaal
 
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
 
Operators_in_Python_Simplified_languages
Operators_in_Python_Simplified_languagesOperators_in_Python_Simplified_languages
Operators_in_Python_Simplified_languages
AbhishekGupta692777
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c language
Tanmay Modi
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
tanmaymodi4
 
Few Operator used in c++
Few Operator used in c++Few Operator used in c++
Few Operator used in c++
sunny khan
 
C operators ppt
C operators pptC operators ppt
C operators ppt
RajniKashyap9
 
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 wave
RahulSharma4566
 
Operators in java
Operators in javaOperators in java
Operators in java
yugandhar vadlamudi
 
Types of operators in C
Types of operators in CTypes of operators in C
Types of operators in C
Prabhu Govind
 
3306617
33066173306617
3306617
shwetakks
 
SPL 6 | Operators in C
SPL 6 | Operators in CSPL 6 | Operators in C
SPL 6 | Operators in C
Mohammad Imam Hossain
 
Operators in Python Arithmetic Operators
Operators in Python Arithmetic OperatorsOperators in Python Arithmetic Operators
Operators in Python Arithmetic Operators
ramireddyobulakondar
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
Kathirvel Ayyaswamy
 

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?
 
power point presentation on topic in C++ called "OPERATORS"
power point presentation on topic in C++ called "OPERATORS"power point presentation on topic in C++ called "OPERATORS"
power point presentation on topic in C++ called "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_in_Python_Simplified_languages
Operators_in_Python_Simplified_languagesOperators_in_Python_Simplified_languages
Operators_in_Python_Simplified_languages
 
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
 
Operators in Python Arithmetic Operators
Operators in Python Arithmetic OperatorsOperators in Python Arithmetic Operators
Operators in Python Arithmetic Operators
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
 

Recently uploaded

J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
Kamal Acharya
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 

Recently uploaded (20)

J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 

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