Numbers
Reference: https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex.
100 #> 100
-100 #> -100
0.45 #> 0.45Numeric Operations
Numeric functions include the usual arithmetic operators:
100 + 5 #> 105
100 - 5 #> 95
100 * 5 #> 500
100 / 5 #> 20
100 + 5 * 2 #> 110
(100 + 5) * 2 #> 210Boolean equality operators also apply:
100 == 100 #> True
100 == 100.0 #> True
100 == 99 #> False
100 == (99 + 1) #> True
True == 1 #> True
False == 0 #> TrueAlso reference the built-in round() function: https://docs.python.org/3/library/functions.html#round.
Formatting as Currency
Use string formatting to control how numbers will display when printed:
Feel free to use (copy-paste) this function definition into your projects:
Advanced Operations
Also reference the numeric functionality of these built-in Python modules:
Last updated
Was this helpful?