Beginner Fundamentals

Numbers

Python has three numeric types: int, float, and complex.

x = 10        # int
y = 3.14      # float
z = 2 + 3j    # complex

int

Integers of unlimited size, positive or negative:

big = 123456789012345678901234567890

float

Numbers with a decimal point. Also supports scientific notation:

a = 1.5
b = 2e3      # 2000.0

Operations

print(7 + 2)    # 9
print(7 - 2)    # 5
print(7 * 2)    # 14
print(7 / 2)    # 3.5  (division always returns float)
print(7 // 2)   # 3    (floor division)
print(7 % 2)    # 1    (remainder)
print(7 ** 2)   # 49   (power)

Handy functions

print(abs(-5))      # 5
print(round(3.7))   # 4
print(pow(2, 10))   # 1024