6/29/22

Python Operators

In programming, there are different types of operators with carry out various functionality.

  • Arithmetic operators

  • Operator Name
    + Addition
    - Subtraction
    * Multiplication
    / Division
    % Modulus
    ** Exponential
    // Floor Division

  • Assignment operators

  • Operator Description
    = Assign value of right side of expression to left side operand
    += Add AND: Add right-side operand with left side operand and then assign to left operand
    -= Subtract AND: Subtract right operand from left operand and then assign to left operand
    *= Multiply AND: Multiply right operand with left operand and then assign to left operand
    /= Divide AND: Divide left operand with right operand and then assign to left operand
    %= Modulus AND: Takes modulus using left and right operands and assign the result to
    left operand
    //= Divide(floor) AND: Divide left operand with right operand and then assign the value(floor)
    to left operand
    **= Exponent AND: Calculate exponent(raise power) value using operands and assign value
    to left operand
    &= Performs Bitwise AND on operands and assign value to left operand
    |= Performs Bitwise OR on operands and assign value to left operand
    ^= Performs Bitwise xOR on operands and assign value to left operand
    >>= Performs Bitwise right shift on operands and assign value to left operand
    <<= Performs Bitwise left shift on operands and assign value to left operand

  • Comparison operators

  • Operator Description
    > Greater than: True if the left operand is greater than the right
    < Less than: True if the left operand is less than the right
    == Less than: True if the left operand is less than the right
    != Not equal to – True if operands are not equal
    >= Greater than or equal to True if the left operand is greater than or equal to the right
    <= Less than or equal to True if the left operand is less than or equal to the right
    is x is the same as y
    is not x is not the same as y

  • Logical operators

  • Operator Description
    and Logical AND: True if both the operands are true
    or Logical OR: True if either of the operands is true
    not Logical NOT: True if the operand is false

  • Membership operators

  • Operator Description
    in True if value is found in the sequence
    not in True if value is not found in the sequence

  • Bitwise operators

  • Operator Description
    & Bitwise AND
    | Bitwise OR
    ~ Bitwise NOT
    ^ Bitwise XOR
    >> Bitwise right shift
    << Bitwise left shift



|

Blog Archive