DEV Community

Ajay
Ajay

Posted on

Python Learning Series | Day-3

What is Operators ?

Operators are special symbol in python used to perform the operation of value and variable.

1) Arithmetic Operator
2) Relational Operator
3) Logical operator
4) Bitwise operator
5) Assignment operator
6) Special operator

1) Arithmetic operator

Used to perform mathematical operation

  • Addition(+)
  • Subtraction(-)
  • Mulitpilcation (*)
  • Division(/) ---> Quotient
  • Floor Division(//)
  • modulus(%) --> Remainder
  • Exponential operator or Power operator (**)
no1 =10
no2 =4

print(no1 + no2)
print(no1 - no2)
print(no1 * no2)
print(no1 / no2)
print(no1 // no2)
print(no1 % no2)
print(no1 ** no2)


Enter fullscreen mode Exit fullscreen mode

output

2) Relational operator 0or Comparison Operator

Compare with the two value , return an boolean value "True" or"False".

  • Greater than (>)
  • Lesser than (<)
  • Greater than or equal to (>=)
  • Lesser than or equal to (<=)
  • Equal to (==)
  • Not Equal to (!=)
no1 , no2 = 10, 20
print(no1 > no2)
print(no1 < no2)
print(no1 <= no2)
print(no1 >= no2)
Enter fullscreen mode Exit fullscreen mode

For This Scenario :

name = "ajay"
name2 = "vijay"
print(name > name2) 
#Dictionaryorder : lexico graphical order
Enter fullscreen mode Exit fullscreen mode

The will compare by an Ascii Value(American Standard code for Information Exchange)

3) Logical operator

used for Conditional statements

  • and --> return True of both condtiton statifies
  • or --> return True of any one condition statifies
  • not --- reverse the boolean result , True to False
no1 , no2 = 0, 20
print(no1 and no2)

print(no1 or no2 )

print(not no1)  # ("no1")  is zero value
Enter fullscreen mode Exit fullscreen mode

4) Bitwise operator

Used to perform operations directly on binary digits (bits) at a low level.

  • AND(&)
  • OR(|)
  • XOR(^)
  • NOT(~)
  • LEFT SHIFT(<<)
  • RIGHT SHIFT(>>)
print(4 & 5)
print(4 | 5)
print(4 ^ 5)
print( ~ 4)
print(4 << 5)
print(4 >> 5)
Enter fullscreen mode Exit fullscreen mode

5) Assignment operator

Used to store value in the variables

  • Standard Assignment ( = )
  • Add and Assign ( += )
  • Subtract and Assign ( -= )
  • Multipe and Assign ( *= )
  • Divide and Assign ( /= )
no1 = 10 

no1 += 5    # no1 = no1 + 5
no1 -= 5    # no1 = no1 - 5
no1 *= 5    # no1 = no1 * 5
no1 /= 5    # no1 = no1 / 5
Enter fullscreen mode Exit fullscreen mode

Top comments (0)