[Solved] What does int() function with 2 args do in Python


The second argument tells int the base of the input string. From the help:

class int(object)
 |  int(x=0) -> integer
 |  int(x, base=10) -> integer
 |  
 |  Convert a number or string to an integer, or return 0 if no arguments
 |  are given.  If x is a number, return x.__int__().  For floating point
 |  numbers, this truncates towards zero.
 |  
 |  If x is not a number or if base is given, then x must be a string,
 |  bytes, or bytearray instance representing an integer literal in the
 |  given base.  The literal can be preceded by '+' or '-' and be surrounded
 |  by whitespace.  The base defaults to 10.  Valid bases are 0 and 2-36.
 |  Base 0 means to interpret the base from the string as an integer literal.

So if you do int(S, B), it says convert S, which is the string representation of a number in base B:

In [63]: int('10', 2)
Out[63]: 2

In [64]: int('10', 3)
Out[64]: 3

Now, if B is larger than 10, then python assumes that the next sequence of digits comes from ABCD.... Thus:

In [65]: int("A", 11)
Out[65]: 10

solved What does int() function with 2 args do in Python