Python | Operators

 

python operator

Python | Operator

Operators are used to Perform Operation on variable or values. like Arithmetic operation , logical Operation

Python Operator Following as Under

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


Arithmetic Operators

It is used for perform mathematical Operation . like division , subtraction, addition etc


Example

i) Addition Operation
   
    a =  5
    b =  5
    c = a + b

    print(c)                

Output
    
    10

ii) Subtraction Operation
   
    a =  5
    b =  5
    c = a - b

    print(c)                

Output   
    
      0


iii) Division Operation
   
    a =  5
    b =  5
    c = a / b

    print(c)                

Output

    1.0


iv) Multiplication Operation
   
    a =  5
    b =  5
    c = a * b

    print(c)                


Output

    25

v) Modulus Operation
   
    a =  5
    b =  5
    c = a % b

    print(c)                

Output
  
    0

vi) Exponentiation Operation
   
    a =  5
    b =  5
    c = a ** b

    print(c)                

Output

    3125



Assignment operators

Assignment Operators are used for assign Values to Variable , like =, =+ etc

Example

i) ' = ' Operator
   
    a =  5
    
    print(a)                


Output

    5

ii) ' += ' Operator
   
    a =  5
    a += 3
    
    print(a)                


Output

    8

iii) ' - = ' Operator
   
    a =  5
    a -= 3

    print(a)                

Output

    2

iv) ' * = ' Operator
   
    a =  5
    a *= 3

    print(a)                

Output

    15

v) ' / = ' Operator
   
    a =  5
    a /= 3

    print(a)                

Output

    1.666666666667

vi) '// = ' Operator
   
    a =  5
    a //= 3

    print(a)                

Output    
    
    1


vii) '** = ' Operator
   
    a =  5
    a ** = 3

    print(a)                


Output

    125


Comparison operators

Comparison Operators are used for Compare Two values

Example

i) ' = =' Equal Operator
   
    a =    5
    b =    6
    
    print(a == b)                

Output
    
    False


ii) ' ! =' Not Equal Operator
   
    a =    5
    b =    6
    
    print(a != b)                

Output

    True

iii) ' < '  Less Than Operator
   
    a =    5
    b =    6
    
    print(a  < b )                

Output

    true

v) ' > ' Greater Than Operator
   
    a =    5
    b =    6
    
    print(a > b )                

Output

    False


vi) '  >=  ' Greater Than or Equal To Operator
   
    a =    5
    b =    6
    
    print(a >= b )                      

Output

    False

vii) '  <=  ' Less Than or Equal To Operator
   
    a =    5
    b =    6
    
    print(a >= b )                


Output

    True

Logical Operator

logical Operator is combine conditional statements , like and , or , not

Example

i) ' and ' logical Operator

Return  True  if both statements are true
   
    a =    5
    b =    6
    c =  5 > 6 and 5 < 6

    print( c)                


Output

    False

ii) ' or ' logical Operator

Return  True  if one of the statements is true
   
    a =    5
    b =    6
    c =  5 > 6 and 5 < 6

    print( c)                

Output

    True


iii) ' not ' logical Operator
 
Return Reverse  Result , if statement is true than return false
    
    a =    5
    b =    6
    c =  not(5 > 6 and 5 < 6)
    d = not(5 > 6 and 5 < 6)

    print( c)                 

Output

    true
Post a Comment (0)
Previous Post Next Post