Explore how int() supports other bases

It’s well known that the built-in function, int(x), attempts to convert x to an integer number. Usually, x is a floating-point number or a string, bytes, or byte-array with a decimal (base ten) representation of an integer number. It’s less commonly known that int() may take the second optional parameter, base. The base must be an integer number ranging from two to 36 (inclusive), or zero.

If the base is a positive number, then the string must contain digits between zero and base-1, or the first base-10 letter of the English alphabet. The letter case doesn’t matter:

Get hands-on with 1200+ tech skills courses.