Operators In Python and It’s Type

1
1081
Operators In Python and It’s Type

Introduction To Operators In Python

Operators In Python are used for performing mathematical operations on numerical data. Suppose to perform the addition of two numbers then operators are used also you want to check that the two conditions in the
operations are True or False then you also use the operators.
Following are the types Operators In Python

  1. Arithmetic Operators
  2. Comparison Operators
  3. Assignment Operators
  4. Logical Operators
  5. Identical Operators
  6. Membership Operator

Arithmetic Operator

Arithmetic Operators In Python

The arithmetic operator is used to calculating some mathematical operations on two or more numerical data.
Following are the Arithmetic Operators:

Addition (+)

Used for the addition of two or more operands

Such as 5 + 6 = 11

Subtraction (-)

Used for the subtraction of two or more operands

Such as 5 – 6 = 1

Multiplication (*)

Used for the multiplication of two or more operands

Such as 3 * 2 = 6

Division ( / )

Used for the division of two numbers, it give us the output of quotient

Such as 10 / 3 = 3.3333

Modulus ( % )

It divide the number but give the output as remainder Like

10 % 3 = 1 , 13 % 5 = 3

Floor Diviation ( // )

It divides the number and give us the round off the value of the quotient

Such as 10 // 3 = 3

Difference between Division and Floor Division

Ex:- Division 15 / 2 Output is 7.5 Floor Division 15 // 2 Output is 7


Widget not in any sidebars

Exponential ( ** )

It gives us the power number in this we pass the two numbers the raise the left number to the power of the right number. Such as 5 ** 2 = 25

Comparison Operators

Comparison Operators

It is used for comparison between two different number or string and it gives the output in True and False term.
Following are the Comparison Operators.

Equal ( == )

It compares two different variables, number or string.

For Example:

  • 1. 5 == 5 is True
  • 2. ‘A’ == ‘a’ is False ( It happen between python is case sensitive language )
  • 3. ‘ABC’ == ‘ABC’ is True

Greater Than ( > )

It checks the left number is greater than the right number and gives output as True or False.

Example:- 5 > 2 is True

Less Than ( < )

It checks the left number is less than the right number and gives output as True or False.

Example:- 5 < 2 is False

Greater Than Equal To ( >= )

It checks the left number is greater than or equal to the right number and gives output as True or False.

For Example:

  1. 5 >= 2 is False
  2. 5 >= 7 is True

Less Than Equal To ( <= )

It checks the left number is less than or equal to the right number and gives output as True or False.

For Example:

  1. 7 <= 3 is True
  2. 8 <= 7 is False

Not Equal ( != )

It check the numbers or variable are not equal to each other.

For Example: .

  1. 8 != 7 is True
  2. 8 != 8 is False

Assignment Operators

Assignment Operators In Python

This operator is used to apply some mathematical operation on the same variable which we already created then simply use assignment operators. Note:- For this first you assign any value to the variable X then apply assignment operator

Following are assignment operators

Equal To ( = )

It used to store values into the variable.

Example: X = 5, Here we assign the 5 into the variable X

Plus Equal To ( += )

It used to Addition of the variable value by any number.

Example: X += 5 is same as X = X + 5

Minus Equal To ( -= )

It used to Subtract the variable value by any number.

Example:- X -= 5 is same as X = X – 5

Multiply Equal To ( *= )

It used to Multiply the variable value by any number.

Example:- X *= 2 is same as X = X * 2

Divide Equal To ( /= )

It used to Divide the variable value by any number.

Example: X /= 2 is same as X = X / 2

Modulus Equal To ( %= )

It used to Divide the variable value by any number and store the reminder to the variable.

Example:- X %= 2 is same as X = X % 2

Floor Equal To ( //= )

It used to Divide the variable value by any number and store the round of the value of the quotient.

Example:- X //= 2 is same as X = X // 2

Logical Operators

Logical Operators In Python

It is used to check both conditions are True or False. It is also known as Bitwise Operators
Following are the Logical Operators

AND ( & )

In the AND operator followers compare the two condition like if the both are true it returns true otherwise false

Rule of and( & )

  • True & True = True
  • False & True = False
  • True & False = False
  • False & False = False

Example:- ( 5 < 4 ) & ( 7 < 5 ) Output is True. Because the both condtions are True

OR( | )

In the OR operator compare the two conditions like if anyone the conditions are true then it returns true. Such as

  • True | True = True
  • False | True = True
  • True | False = True
  • False | False = False

Example:- ( 5 < 7 ) | ( 7 < 5 ) Output is True. Because out of the two conditions one condition is true so according to OR operator Rule If anyone of it True It Returns True

NOT ( ~ )

It inverse the result of AND and OR Operators

Example:- Z = 3 not(( Z < 5 ) and ( Z < 10)) Output is False.

Explanation:- According to AND operator both conditions are True but when to apply NOT it inverse the result so the output is False.

Identical Operators

An identical operator is used to compare the two different values or variables.

There are two different types of Identical operators

  • 1. is
  • 2. is not

Example:

  • 1. 5​ is​ 50 the output is False
  • 2. 5​ is not ​50 output is True

Membership Operators

It identify the values are present into the variable or not

There are two different types of Membership operator

  • 1. in
  • 2. not in

Example:-

  • ‘fire’​ in​ ‘fireblaze’ output is True
  • ‘fire’ ​not in​ ‘fireblaze’ output is False

Widget not in any sidebars

Conclusion

In this blog, Coverall operators in python used to perform mathematical or conditional operations on the variable or number. It will help you to understand of how operators are used in Python

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here