Math (built-in)

Basic Math in Python works as you expect it will:

+ adds

- subtracts

* multiplies

/ divides

x**y raises x to the exponent y

( ) work like they should

% modulo - gives remainder of division

Also works as expected


  1. Parentheses

  2. Exponents (or unary operators)

  3. Multiplication and Division

  4. Addition and Subtraction

  5. Left to Right

3*(4+5) is not the same as (3*4)+5, as you’d expect.

Don’t forget that you have to use * to multiply

For instance, in math: 3(4+5) is fine… in programming, you need 3*(4+5)

Use math in any expression where a numeric is expected.

Recent Posts