Python Operators

Python Operators -:-Python Operators-:-

Python Operators :-

  1. Arithmetic Operator.
  2. Assignment Operator.
  3. Comparison Operator.
  4. Logical Operator.
  5. Identity Operator.
  6. Membership Operator.
  7. Bitwise Operator.
  1. Python arithmetic operator :-

  2. 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

  3. Python assignment operator :-

  4. Operator Example Same as
    = 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

  5. Python comparision operator :-

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

  7. Python logical operator :-

  8. Operator Description Example
    and Return True it both
    statements are true
    x < 5 and x >10
    or Retuens True if one of
    the statements is true
    x < 5 or x < 4
    not Reverse the result, returns
    false if the result is true
    not ( x < 5 and x<10 )

  9. Python identity operator :-
  10. Identity operators are use 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 Return True if both variable
    are the same object
    x is y
    is not Return true is both variable
    are not the same object
    x is not y

  11. Python membership operator :-

  12. 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

  13. Python bitwise operator :-

  14. Operator Name Example
    & Bitwise and x & y
    | Bitwise or x | y
    ~ Bitwise not ~x
    ^ Bitwise xor x ^ y
    >> Bitwise right shift x>>
    << Bitwise left shift x<<

Comments

Popular posts from this blog

javascript

Python literals