Python Operators Briefly Explains With Example

Python Operators Briefly Explains With Example
Python Operators Briefly Explains With Example

    Python Operators Briefly Explains With Example

    Python Operator: A python operator is a Special operator is a mathematical operation performed in the python language. 

    Operator Can be used to solve the mathematical operation Perform logically. The operator has used variables and data calculation.


    Types Operator in Python Language.

    1. Arithmetic Operator


    2. Relational Operator


    3. Logical Operator 


    4. Assignment operator


    5. Bitwise Operator


    6. Identity Operator


    7. Membership Operator


    Arithmetic operator in Python Language

    Arithmetic Operator: A arithmetic operation is a used mathematical operation performed. It is many operations performed like additionsubtraction, multiplication, and division.

    Important Same Other Languages Operator 

    👉C++ Operators 

    👉Java Operators 

    👉C Operators


    Example of Arithmetic operator

    Addition:a+b or 10+10=20
    Here a is operands value (+) Addition is operator and b is operands. It can be used for additional operations performed.

    Subtraction:a-b or 20-10=10
    Here a is operands value (-) Subtraction sign is operator and b is operands. It can be used as Subtraction operations performed.

    Multiplication:*b or 10*10=100
    Here a is operands value (*) Multiplication sign is operator and b is operands. It can be used Multiplication operations performed.

    Division:a/b or 10/5=2
    Here a is operands value (/) Division sign operator and b is operands. It can be used for Division operations performed.

    Modulas:a%b or 10%3=1
    Here a is operands value (%) Modules sign operator and b is operands. It can be used Modules operations performed.

    Arithmetic Operator  Table

    Sign.      Operation.    Example


    (+)           Addition            (a+b)


    (-)            Subtraction      (a-b)   


    (*)           Multiplication   (a*b)


    (/)            Division             (a/b)


    (%)         Modules            (a%b)


    (//)           Floor Division  (a//b)


    (**)         Exponent           (a**b)


    How To Use Arithmetic Operator in Python?

    x=15


    y=4;


    print("Addition:,(x+y)) 


    print("Subtraction:",(x-y)) 


    print("Multiplication:"(x*y)) 


    print("Division:",(x/y))


    print("Modulus:",(x%y))


    print("Floor:",(x//y))


    print("Exponent:",(x**y))


    *****OUTPUT*****


    Addition:19


    Subtraction:11


    Multiplication:60


    Division:3.75


    Modulus:3


    Floor:3


    Exponent:50625


    Relational Operator in Python Language

    Relational Operator: Relational operators are used in comparison to the two operands.
    It can be using equal operands and condition check in this operator. Relational operator very most and useful operator.

    Relational Operator  Table

    Sign.   Operation.    Example


    (==)     Equal To               (a==b)


    (!=)     Not 
    Equal To       (a!=b)   


    (>)      Grater Than        (a>b)


    (<)       Less Than             (a<b)


    (>=)    Grater than         (a>=b)


    (<=)     Less Than           (a<=b)

     
    How To Use Relational Operator in Python?

    a=10;


    b=20;


    print("a>b is:",a>b)


    print("a<b is:",a<b)


    print("a>=b is:",a>=b)


    print("a<=b is:",a<=b)


    *****OUTPUT*****


    a>b is: False


    a<b is: True


    a>=b is:False


    a<=b is:True


    Logical Operator in Python Language

    Logical Operators: Python provides three logical operators. logical Operator tests more than one condition to make decisions.

    Types of Logical Operator

    1.and Operator 

    2.or Operator 

    3.not Operator 

    AND Operator: AND Operator can be used decisions are two values.AND Operator two values are True AND Operator return True. But two values are anyone False AND Operator return False.

    OR Operator: OR operator performs a logical condition on two expressions. if or Operator can be two expressions are True OR Operator return true. But any of the expressions are False OR Operator return True.

    NOT Operator: NOT operator is a very easy Operator. it can be used conditions True NOT Operatorreturnsn False and the condition is False NOT Operator returns True.

    How To Use Logical AND Operator in Python?

    a=True

    b=False

    print( "a and b is:",a and b)

    print( "a or b is:",a or b)

    print( "not a is:",not a )

    *****OUTPUT*****


    a and b is: False


    a or b is: True


    not a is: False


    Bitwise Operator in  Python Language

    Bitwise Operator: A Bitwise operator is an operation performed on the data bit level. the bitwise operator is also shifted bit right to left.

    Note: Bitwise operators are not allowed to float and double.

    Python Bitwise Operator  Table

    Sign.     Operation       Example


    (&)       Bitwise AND        (a&b)


    (|)        Bitwise OR           (a|b)   


    (<<)      Bitwise LEFT       (a<<2)


    (>>)      Bitwise RIGHT    (a>>2)


    Python Assignment Operator  Table

    Sign.       Operation.   Example


    (=)            a=b                (a=b)


    (+=)          a+=b             (a=a+b)   


    (-=)           a-=b              (a=a-b)


    (*=)          a*=b              (a=a*b)


    (/=)           a/=b              (a=a/b)


    (%=)         a%=b           (a=a%b)


    Python Identity Operator 

    Sign.                    Example


    (is)                       (a is True)


    (is not)               (a is not True)


    How To Use Identity Operator in Python?

    a=10

    b=10

    a1='icoderweb'

    b1='icoderweb'

    a2=[1,2,3]

    b2=[1,2,3]

    print( a is not b)

    print( a1 is b1)

    print( a2 is b2 )

    *****OUTPUT*****


    False


    True


    True


    Membership Python Operator 

    Sign.             Example


    (in)               (10 in a)


    (not in)        (10 not in)


    How To Use Membership Operator in Python?

    a='icoderweb'

    b={1:'a',2:'b'}

    print( 'c' in a)

    print( 'b' in a)

    print( 1 in b )

    *****OUTPUT*****


    True


    True


    True


    Post a Comment

    0 Comments
    * Please Don't Spam Here. All the Comments are Reviewed by Admin.