Topic 4
Topic 4
Operator
• An operator is a symbol. The python interpreter identifies operator and
performs a specific mathematical or logical operation. The python
programming language provides the following operators.
• Arithmetic operator
• Comparison operator
• Assignment operator
• Logical operators
• Bitwise operators
• membership operators
• Identity operators
Arithmetic Operators
Operator Description
+ Addition Adds values on either side of the operator
// Floor Division
Comparison Operators
Operator Description
== If the values of two operands are equal, then the condition becomes true.
!= If the values of two operands are not equal, then the condition becomes true
If the value of the left operand is greater than the value of the right operand
> then the condition becomes true
If the value of the left operand is less than the value of the right operand then
< the condition becomes true
If the value of the left operand is greater than or equal to the value of the
>= right operand then the condition becomes true
If the value of the left operand is less than or equal to the value of the right
<= operand then the condition becomes true
Assignment Operators
Operator Description
+= It adds right operand to the left operand and assigns the result to left operand
-= It subtracts right operand to the left operand and assigns the result to left operand
*= It multiplies right operand to the left operand and assigns the result to left operand
/= It divides right operand to the left operand and assigns the result to left operand
%= It takes modulus using two operand and assigns the result to left operand
**= It performs exponential calculation on operators and assign the value to the left operand
//= It performs floor division on operators and assign the value to the left operand
Bitwise Operators
Operator Description
Binary AND Operator copies a bit to the result if it exists in both
& operands
| Binary OR It copies a bit if it exists in either operand
Operator Description
Logical AND If both operands are true then condition becomes
and true
Logical OR If any two operands are non-zero then condition
or become true
not Logical NOT used to reverse the logical state of its operand
Membership Operators
Operator Description
Evaluates to true if it finds a variable in the specified sequence and
In false otherwise
Evaluates to true if it does not find a variable in the specified
not in sequence and false otherwise
Identity Operators
Operator Description
Evaluates to true if the variables on either side of the operator
is point to the same object and false otherwise.
Evaluates to false if the variables on either side of the operator
is not point to the same object and true otherwise