What is the logic behind
int("string", integer)
for example:
int("220", 3)
yields
24
What is the logic behind
int("string", integer)
for example:
int("220", 3)
yields
24
The optional integer is the numeric base to use in converting the string (defaults to base 10).
220 base 3 = 2 * (3**2) + 2 * (3**1) + 0 * (3**0)
= 2*9 + 2*3 + 0*1
= 18 + 6 + 0
= 24
the int() method in python takes two inputs. First is the string you want to evaluate the second is the base.
In your example the base is three therefore:
1*0 = 0
3*2 = 6
9*2 = 18
0 + 6 + 18 = 24