Numbers

An int has no size limit. 2 ** 100 is exact, so you never worry about overflow in Python, a fact worth saying out loud in an interview.

A float is a 64-bit binary fraction, so 0.1 + 0.2 is not exactly 0.3. Compare floats with a tolerance, such as math.isclose, never with ==.

  • / always gives a float. // is floor division and % is the remainder. Both round toward minus infinity, so -7 // 2 is -4.
  • divmod(a, b) gives both at once.
  • ** is power. abs drops the sign.
  • round uses banker's rounding: halves go to the even neighbour, so round(2.5) is 2.

Run it, then try -7 % 2 and round(3.5).