§ 2.2.1section 3 of 18·~3 min
Numbers, strings and booleans
| Type | Example | Use it for |
|---|---|---|
int | 42 | counts, IDs, quantities |
float | 3.14 | prices, measurements |
str | "Pune" | names, raw text |
bool | True | flags and checks |
Numbers support the usual maths. / always gives a float, // divides and drops the remainder, and % gives just the remainder. Comparisons like > and == give back a bool.
print(7 / 2) # 3.5
print(7 // 2) # 3
print(7 % 2) # 1
print(10 > 3) # True
watch out Floats aren't exact: 0.1 + 0.2 gives 0.30000000000000004. For money, real pipelines store amounts as whole paise in an int, or use the Decimal type.