Python Basic Operator
Hello friends, In this lecture, we will discuss
python basic operator.
Operators are constructed to manipulate the value of
operands.
For example Consider 1+2=3. Here 1 & 2 are
operands and + is the operator.
Types of the operator:
There are seven types of the operator in python.
 · Arithmetic Operator
 · Assignment Operator
 · Bitwise Operator
 · Comparison Relational Operator
 · Identity Operator
 · Logical Operator
 · Membership Operator
Now discuss all the operator one by one.
Arithmetic Operator:
Operator

Description

+(Addition)

Add
the values

(Subtraction)

Subtract the values

*(Multiplication)

Multiples
the values

/(Division)

Divide
the values

%(Modulus)

Divides
lefthand value by righthand value and returns the remainder

**(Exponent)

Exponential
power calculation

//(Floor
Division)

After
division result is the quotient after the decimal point is removed. But a
negative result is floored

Example:
Output:
Assignment Operator:
Operator

Description

=

Assign
the value from right to left side operands

+=(Add
AND)

It
add value from right to left operands and it is stored in left operand

=(Subtract
AND)

It
subtract value from right to left operands and it is stored in left operand

*=(Multiply
AND)

It
multiply value from right to left operands and stored in left operand

/=(Division
AND)

It
divide value from right to left operands and stored in left operand

%=(Modulus
AND)

It
modulus two operands and assign the value in left operand

**=(Exponent
AND)

It
perform exponential power calculation on operators and assign value in left
operand

//=Floor
Division

It
floor division on operators and assign value in left operand

Example:
Output :
Bitwise Operator:
Bitwise operator works on the bit. It is performed
bit by bit operation.
Operator

Description

&(Binary
AND)

Operator
copies the bit in result if it exist in both operands

(Binary
OR)

Copies
the bit if it exist in either operands

^(Binary
XOR)

Copies
the bit if it is set in one operand, but not in both operands

~(Binary
Ones Complement)

It
is the unary and effect of the flipping bits

<<(Binary
Left Shift)

The
left operand value move left by number of bits, it is specified by right
operand

>>(Binary
Right Shift)

The
left operand value move right by number of bits, it is specified by right
operand

Example :
Output :
Comparison Relational Operator :
These operators compare the value and decide the relation to among them. These
operators are known as Comparison relational operator.
Operator

Description

==

If
two operands value are equal then condition become true

!=

If
two operands value are not equal then condition become true

<>

If
two operands value are not equal then condition become true. It is similar to
!= operator

<

If
left operand value less than right operand, then condition become true

>

If
left operand value greater than right operand, then condition become true

<=

If
left operand value less or equal than right operand, then condition become
true

>=

If
left operand value grater or equal than right operand, then condition become
true

Example :
Output:
Identity Operator:
These operator used for compares the memory location
of objects.
Operator

Description

Is

If
evaluates true, variables on operator point to object otherwise false

is
not

It
evaluates false, variables on operator point to the object otherwise true

Example:
Output:
Logical Operator:
These operators used to reverse the logical state of
the operand.
Membership Operator:
Operator

Description

in

It
evaluates true if find the variable in the specified sequence and false
otherwise

not
in

It
evaluates true it does not find the variable in the specified sequence and
false otherwise

Next:
In next lecture, we will discuss Python Decision Making.