Operators and f-strings
| add, subtract, multiply | + - * |
| division (always a float) | / |
| floor division / remainder | // % |
| power | ** |
PYTHON
print(17 / 5) print(17 // 5) print(17 % 5) print(2 ** 10)
Comparisons return True or False, and you can combine them with and, or and not.
PYTHON
print(5 > 3, 5 == 3, 5 != 3) print(True and False, True or False, not True)
An f-string is the easiest way to mix text and values: put f before the quotes and variables inside { }. You can format too: :.2f for two decimals, :, for thousands separators.
PYTHON
name = "Omar" salary = 9500 print(f"{name} earns {salary} SAR") print(f"Yearly: {salary * 12:,}") print(f"VAT 15%: {salary * 0.15:.2f}")