Numeric Types

We’ll start with numeric types, which you are probably pretty comfortable with. We’ll focus on these in Python 3:

  • int: an integer or whole number

  • float: a number with a possible fractional part (digits after the decimal point)

Literals are what we call fixed values that do not change, of a type.

  • Example int literals: 3, -52, 103495, 882301

  • Example float literals: 3.0, -5.2, 103.495, .882301

This table summarizes the operators we can use with numeric types:

Order of precedence in Python

When evaluating a numeric expression, the order in which the operators are applied depends on what the operator is. If an expression has exponentiation, that is done first. Next are the multiplicative operators, which are done left to right. Finally, there are addition and subtraction.

  • **

  • *, /, //, %

  • +, -


Here are some examples:

If you want to evaluate expressions in an order other than their normal precedence, you can group expressions in parentheses. The parenthetical expression will be evaluated before it is used.

Here are some examples: