Python Operator and its types

Python Operator and its types

Hey Guys! If you are worried about Python Operator and its types than you are on right place to learn. Here You will learn all python operators in details.

What is Operator ?

  • An Operator is a symbol that tells the compiler to perform specific mathemetical or logical function.Operator can be unary,binary or ternory.
  • The operator which requires a single operand is known as a unary operator (++x).
  • The Operator requires two operands is known as binary operator(a+b)
  • The Operator requires three operands is called ternary operator.




Types of Operator

  1. Arithmatic Operator
  2.  Relational Operator
  3.  Assignment OperatoR
  4.  Logical Operator
  5.  Bitwise Operator
  6.  Membership Operator
  7.  Identity Operator

1. Arithmatic Operator

Operator Name Example
+ Addition x + y
Subtraction x – y
* Multiplication x * y
/ Division x / y
% Modulus x % y
** Exponentiation x ** y
// Floor division x // y

For Practical and examples of Arithmatic Operator watch our Python classes on youtube click on the below link for all Python classes

Python All Classes

2. Relational Operator

Operator Name Example
== Equal x == y
!= Not equal x != y
> Greater than x > y
< Less than x < y
>= Greater than or equal to x >= y
<= Less than or equal to x <= y

C. Assignment Operator

= x = 5 x = 5
+= x += 3 x = x + 3
-= x -= 3 x = x – 3
*= x *= 3 x = x * 3
/= x /= 3 x = x / 3
%= x %= 3 x = x % 3
//= x //= 3 x = x // 3
**= x **= 3 x = x ** 3
&= x &= 3 x = x & 3
|= x |= 3 x = x | 3
^= x ^= 3 x = x ^ 3
>>= x >>= 3 x = x >> 3
<<= x <<= 3 x = x << 3



For Live Class click on the link below

Assignment Operator Vs Relational Operator

4.Logical Operator

Logical operators are used to combine conditional statements:

i) ‘and’ operator

first operand                            second operand                     Result
True                                            True                                          True
True                                            False                                         False
False                                           True                                          False
False                                           False                                         False

ii) ‘or’ Operator

first operand                           second operand                      Result
True                                          True                                           True
True                                          False                                          True
False                                         True                                           True
False                                         False                                          False

iii) ‘not’ operator-Reverse the result, returns False if the result is true.

5. Bitwise Operator

Bitwise operator are used to perform bitwise calculations. These operators are applicable only for ‘int’ and ‘bool’ type only.These operator are also called binary operator.

AND operator—-return 1 if both bits are 1 otherwise 0

Example—10—-1010
3— 0011
—————————–
1010
&
0011
=====
0010 2(decimal)
=====

OR operator–return 1 if any of the bits is 1.If both the bits are 0 then
========== it return 0

1010
|
0011
=====
1011======11(decimal)
====

XOR operator—-return 1 if bits are different otherwise 0
=============

1010
^
0011
=====
1001 (9 decimal)
====




6. Membership Operator

Membership operators are used to test if a sequence is presented in an object:

Operator Description Example
in Returns True if a sequence with the specified value is present in the object x in y
not in Returns True if a sequence with the specified value is not present in the object x not in y

7. Identity Operator

Identity operators are used to compare the objects, not if they are equal, but if they are actually the same object, with the same memory location:

Operator Description Example
is Returns true if both variables are the same object x is y
is not Returns true if both variables are not the same object x is not y

I hope you will understand the topic Python Operator and its types well. For More Python Lecture Subscribe Our Youtube Channel click on the link-

Youtube Channel



Also Check the Below Article

Top 10 Python Programs

Python input from command line

 

Leave a Comment