Parse String to Int Base in Python

The int() function in Python converts a string to an integer. But this function has the second default parameter: base. The base can be between 2 (you need to have at least 2 different values) and 36 (numbers + letters). The default value is 10.

Both examples return the same result:

Result:

This means, by how many elements the value will be represented. Look at the following table to see how it works.

 Base  available numbers and letters
 2  01
3 012
4 0123
5 01234
6 012345
7 0123456
8 01234567
9 012345678
10 0123456789
16 0123456789abcdef
20 0123456789abcdefghij
36 0123456789abcdefghijklmnopqrstuwvxyz

Now, take a look at the following examples:

All of these lines return the same result, which is 9999.

If you want to convert an integer to binary (2), octal (8), hex (16) or any other base between 2 and 36, you can use the following function.

Now use the following code to display values.

It will return the following result.