Numbers

Posted on September 06, 2021



Python includes three numeric types such as integers int, float float, and complex complex numbers.

# an integer
a = 2

# a float
b = 3.89

# a complex number
c = 2 + 5j

Underscore

# use underscores to represent commas
>>> million = 1_000_000
>>> million
1000000

Round a number

# round to a whole number
>>> round(1875.82)
1876

>>> round(1875.82, -2)
1900.0

# round to a decimal place
>>> round(1875.82, 1)
1875.8


Back


Gavin Wiggins © 2021