Python literals

Module 2 · Python literals · Lesson 2 of 6

Integers

An integer — Python calls the type int — is a whole number. 0, 42, -7: positive, negative, or zero, but never with a fractional part.

Whole numbers, evenly spaced
-3
-2
-1
0
1
2
3
Big numbers are hard to read, so Python lets you group digits with underscores: 1_000_000 means the same as 1000000.

You write them just as you'd expect — no commas, no spaces. A minus sign makes one negative. There's no practical limit on how big they get: Python handles enormous integers without breaking a sweat.

Two small things to avoid: don't start an integer with a leading 0 (Python reserves that for other number bases), and use _ rather than commas to group digits. Next up, what happens when a number does have a decimal point.