He does exactly what he says - converts a string into an integer into a given number base. According to the documentation, int() can convert strings to any base from 2 to 36. At the lower end, base 2 is the lowest useful system; base 1 will only have “0” as a character, which is useless to count. At the upper end, 36 is chosen arbitrarily, because we use characters from "0123456789abcdefghijklmnopqrstuvwxyz" (10 digits + 26 characters) - you can continue with a large number of characters, but it is not clear what to use after z.
The "normal" math is base-10 (uses the characters "0123456789"):
int("123", 10) # == 1*(10**2) + 2*(10**1) + 3*(10**0) == 123
Binary base-2 (uses the characters "01"):
int("101", 2) # == 1*(2**2) + 0*(2**1) + 1*(2**0) == 5
"3" does not make sense in base 2; it uses only the characters "0" and "1", "3" is an invalid character (sort of trying to make an appointment by January 34th).
int("333", 4) # == 3*(4**2) + 3*(4**1) + 3*(4**0) # == 3*16 + 3*4 + 3*1 # == 48 + 12 + 3 # == 63
Hugh bothwell
source share