Complete instructions of Python Operators

python operators
Instruction of python operators

Defined Python operators

The operators are defined as symbols that can multiply the value of the operant. Here including values that an operator acts on are called operants. All operations are used to perform variables and values. 

For the example of – 12 + 7 = 19, here ‘+’  sign is the operator, 12 and 7 that are called operands and output 19 is the operation.  

print(12 + 7)

Output – 19

Key Points:-

  • # Python operators basic
  • Operation types of python
  • Example of every types operators

Types of Python Operators

Operators work as a pillar of a program that is built-in separate code. Python provides the a variety of programs that including below – 

  1. Arithmetic Operators
  2. Assignments Operators
  3. Comparison/ relational operators
  4. Logical Operators
  5. Membership Operators
  6. Identity Operators
  7. Bitwise Operators

Let’s go to see all the operators one by one.

Arithmetic operators

When we want to use mathematical operators including a python, here you need to add a numeric variable that is called Arithmetic operators. The basic thing of operations needs to be operated. 

Arithmetic operators including points are additions (+), subtraction (-), multiplications (*), divide (/), reminder (%), exponent (**), floor division (//) operators.

Addition (+)Add two operands12 + 719
Subtraction (-)Right from left operands subtract12 – 7   5
Multiplication (*)Multiples values either site12*784
Divide (/)Divides left by the right operands7/121.7142
Reminder (%)Divided left and right and right operands and return reminder12%75
Exponent (**)Performed power calculation on operands12**7 (12 to the power 7)35831808

Assignments Operators

These operators are assigned two value operators. It is the various component operators in python  

Operators (Symbol)ExplanationExample
=Assign from right side to left side operendsA = 12 
+=(add AND)Add right to left operends and assign result leftA = a + 12
-= (add subtract)Subtract Right to left operands and assign the result to left A = a – 12
*= (Multiply add)Multiply right to left operates and assign result leftA= a*12
/= (divide AND)Divide left to right operand and assign result leftA = a/12
%=Reminder right to left operends and assign valuesA = a%12
**= (exponent AND)Power calculations on operators values and assign resultA = a **12
//= (floor division)Performs floor division and assign valuesA = a//12
&= Assign right and left operands and assign valuesA = a&12

Comparison/ relational operators

Comparison/ relational operators compare the values of either site and show the result either TRUE and FALSE according to these two conditions. Basically, Comparison operators compare two values.

Example of comparison operators – 

Operators ExplanationExample
==When two operands are equal that value is truea==b
>Getter than a>b
<Less thana<b
!=Not equala!=b
>=Getter than or equal toa>=b
<=Less than or equal toa<=b

Logical Operators

These operators are used to combine conditional statements. Basically, these operators used to make a decision. Python supports three logical operators ‘and’, ‘or’, ’not’ operators.

For Example of logical operators –



print( a and s is a and s)

The Output of these- 

a and b is False

ANDReturn result TRUE when both statements are truea<10 and a<20
ORReturn result TRUE when one of the statements is truea<9 or a<8
NOTReverse the return result if FALSE then result is truenot(a<10 and a< 20)

Membership Operators

These operators are used to test if a sequence was an object (like string, set, list, tuple, dictionary). There are two kinds of python membership operators ‘in’ and ‘not in’. 

Example of python membership operators – 

p= ‘Hello WigMarketing team’

q = {5:’x’, 6: ‘y’}

# output is True

print(‘H’ in p)

# output True

print(‘hello’ not in p)

# output: True

Print (5 in q)

Operators ExplanationExample
inWhen the sequence value is an object detected the result of this operand is a TRUE objecta in b
Not inWhen the sequence value has not detected the operands that result showing Truea not in b

Identity Operators

These operators compare the object not if operands are equal. Here all operands are the same object and same memory location but not equal. Including two variables are equal but not implied. 

There are two kinds of python identity operators ‘is’ and ‘is not ’. 

Example of the two operators – 

A1 = 6

B1 = 6

Output : False

Print (a1 is not b1)

OperatorsExplanation Example
isWhen both operands are the same object then result Truea is b
Is notWhen both operands are not the same object or value then result Truea is not b

Bitwise Operators

Normally, used these operators when I need to compare binary numbers. It works as bit-by-bit operations.

Example of the bitwise operator in python

If x = 8

y = 7

Then, 8(decimal)= 1000

And 7 (decimal) = 0111

Hence, x& y = 1111

Operators (meaning)ExplanationExample
& (AND)All operands bit to 1 if both bits are 10000, 0000
| (OR)Each bit to 1 if one of two bits is 10000, 1000
<< (LEFT SHIFT)Binary left shift0010, 1000
>>(RIGHT SHIFT)Binary right shift0000.0010
~ (NOT)Inverts all bits1111, 0101
^ (XOR)Each bit is 1 if only one bit to 10000, 1110

I think this article would be helpful, I believe in the quality of content. If there are any mistakes please let us know through the comment section. We are eagerly waiting to reply to you with a great update.

Leave a Reply