Integer and float literals
A number without a dot is an int, a number with a dot is a float, and Python tells them apart as it reads your code.
Used in 129 lessons of the course, from 00.01.
A literal is a value written directly in your code. 3 is an integer literal (int). 0.6 is a decimal literal (float).
The rule is short: if there is a decimal point, it is a float. If there isn't, it is an int. So 2 and 2.0 are equal in value, but they are different types.
An int is exact and has no size limit. A float is an approximation, so 0.1 + 0.2 is not exactly 0.3.
You can use underscores to make a big number readable: 1_000_000.
In the course you see them in calls like get_close_matches(key, GLOSSARY.keys(), n=3, cutoff=0.6). There n=3 is an integer (how many results) and cutoff=0.6 is a float (how similar a match must be, from 0 to 1). Picking the right type matters because each parameter expects one.
Reach for it when: you need to write a quantity in your code: an `int` for counting things, a `float` for measurements and thresholds.
Examples
Common mistake
print(1,000)
Why: The comma separates arguments, not thousands. Python prints two numbers: 1 and 0.
How to write it: Write 1000 or use an underscore: 1_000.
Common mistake
print(007)
Why: A decimal integer can't start with leading zeros. Python rejects it.
How to write it: Write 7. If you need the zeros, use a string or an f-string with a format spec.
