Python Operators

Python Operators

  • Used to perform operations to strings, numbers, and even statements

  • 4 types:

    • Arithmetic Operators

      • Used for mathematical operations like addition, subtraction, and others

      • + (Addition)

      • - (Subtraction)

      • * (Multiplication)

      • / (Division)

      • % (Modulus)

      • ** (Exponentiation)

      • // (Floor Division)

    • Assignment Operators

      • Used to assign values to a variable

      • =

      • +=

      • -=

      • *=

      • /=

      • %=

      • //=

      • **=

    • Relational/Comparison Operators

      • Return a Boolean either True or False

      • > returns TRUE if the left operand is HIGHER than the right operant

      • < returns TRUE if the left operand is LOWER than the right operand

      • == returns TRUE if the two operants are EQUAL

      • != returns TRUE if the two operands are NOT EQUAL

      • >= returns TRUE if the left operand is HIGHER THAN OR EQUAL to the right operand

      • <= returns TRUE if the left operand is LOWER THAN OR EQUAL to the right operand

    • Logical Operators

      • Used to combine conditional statements and returns a Boolean either True or False

      • and returns TRUE if BOTH of the statements or expressions are TRUE

      • or returns TRUE if ONE of the statements or expressions is TRUE

      • not REVERSES the results, returns FALSE IF TRUE and TRUE IF FALSE