Operators are used to perform operations on variables and values.

Python divides the operators in the following groups:

  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Logical operators
  • Identity operators
  • Membership operators
  • Bitwise operators

ARITHMETIC OPERATORS :

  • + addition
  • − subtraction
  • * multiplication
  • / true division
  • // integer division
  • % the modulo operator

The use of addition, subtraction and multiplication are pretty straightforward. The result will be in the data type of the operands on which the operation has been done.

/ — reports the result of the expression in the float data type. Eg : 27/4 results in the float value 6.75.

% — reports the remainder of the expression. Eg : 5%2 results in 1.

//( integer division ) — as the name indicates, it reports the result in the integer data type. The floor division ,which rounds the result down to the nearest whole number is performed. Eg : 15//2 results in 7.

LOGICAL OPERATORS : (AND, OR, NOT)

These are made use in conditional statements and loops.

and — returns True if both statements are true Eg : x < 5 and x < 10

or — returns True if one of the statements is true Eg : x < 5 or x < 4

not — reverse the result, returns False if the result is true Eg : not(x < 5 and x < 10)

MEMBERSHIP OPERATORS : ( in and notin )

in — returns TRUE if the value/variable is found in the sequence.

notin — returns FALSE if the value/variable is not found in the sequence.

IDENTITY OPERATORS : (is and isnot)

is — returns TRUE if both the objects are identical.

isnot — returns TRUE if both the objects are not identical.

NOTE : IT WILL CHECK FOR EQUALITY.

DIFFERENCE BETWEEN IDENTICAL AND EQUAL :

The assignment operator (==) checks for equality whereas is and isnot checks whether they are identical.

Example :

a=[1,2,3]

b=a

c=[1,2,3]

print(a==b) — — TRUE ( a is equal to b)

print(a is b) — — TRUE ( a is identical to b)

print(a==c) — TRUE (a is equal to c)

print(a is c) — FALSE (a is not identical to b)

REMAINING OPERATORS WILL BE COVERED IN THE NEXT POST.

Leave your feedback here : harini.official.id@gmail.com

Follow me on Linkedin : https://www.linkedin.com/in/harini-ravichandran-2568a11a7/

Aspiring Software Developer — Python Developer — Let’s learn together