Numbers
Numbers in Python
Python has two main number types: integers (whole numbers) and floats (decimal numbers). You can perform math operations on both.
python
# Integers
x = 10
y = 3
print(x + y) # Addition: 13
print(x - y) # Subtraction: 7
print(x * y) # Multiplication: 30
print(x / y) # Division: 3.333...
print(x // y) # Floor division: 3
print(x % y) # Modulus (remainder): 1
print(x ** y) # Power: 1000Floats
Floats are numbers with decimal points. When you divide two integers, Python automatically returns a float.
python
price = 19.99
tax_rate = 0.08
total = price + (price * tax_rate)
print(f"Total: ${total:.2f}")Tip:Use // for integer division (floors the result) and % to get the remainder. These are super useful in programming!
PlaygroundPython
Output
Click "Run" to see output