5. Operators

5.1 Arithmetic Operators

  • // Integer dicision

  • % Remainder (modulo)

  • ** Exponent

5.2 Bitwise Operators

  • & and

  • | or

  • ^ xor

  • << shift left

  • >> shift right


  • not the same as logical operators

  • they operate on bits.

  • x = 0x0a implies x is a hexadecimal number

  • use prefix 0b for binary numbers

  • strings can be formatted in

    • hex as print(f'(hex) x is {x:02x}, y is {y:02x}, z is {z:02x}')

    • binary as print(f'(bin) x is {x:08b}, y is {y:08b}, z is {z:08b}')

5.3 Comparison Operators

  • Equal: ==

  • Not equal: !=

  • Less than: <

  • Greater than: >

  • Less than or equal: <=

  • Greater than or equal: >=

5.4 Boolean Operators

  • and, or, not (no xor for boolean operators)

  • in, not in, is, is not

5.5 Operator Precedence

  1. Arithmetic

  2. Bitwise

  3. Comarpsions

  4. Boolean