Integers and Floats
Python has two main numeric types: int for whole numbers and float for numbers with decimals. Python handles both seamlessly.
x = 42
y = 3.14
print(x)
print(y)
print(type(x))
print(type(y))
Try it Yourself →
Mathematical Operations
Python supports all standard math operations: addition, subtraction, multiplication, division, exponentiation, and floor division.
a = 10
b = 3
print(a + b)
print(a - b)
print(a * b)
print(a / b)
print(a // b)
print(a % b)
print(a ** b)
Try it Yourself →
Random Numbers
Python's random module gives you access to random number generation. Import it and use randint() or random().
import random
print(random.randint(1, 10))
print(random.random())
print(random.choice(["apple", "banana", "cherry"]))
Try it Yourself →