how does the built-in function: int(s, base) works? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how does the built-in function: int(s, base) works?

I was going thru the use of this function but want alter to figure out how it works... for e.g. int("A9",13) will give the result: 139 and, int("B7", 17) will give .. 194 so, could some one pls. explain how come this actually happened.. Many Thanks, Adarsh :)

5th Jul 2016, 6:08 PM
Adarsh Namdev
Adarsh Namdev - avatar
3 Answers
+ 3
This function has two arguments. The first argument is how the number is displayed, the second one: the base the number is written in. From examples given in question: A9 in base 13 is 139 and B7 in base 17 is 194. I hope I helped.
5th Jul 2016, 7:01 PM
Sławek Śpiewak
Sławek Śpiewak - avatar
+ 2
One more thing. Attemting to put ciphers from wrong base eg 9 in base 8 raises ValueError.
5th Jul 2016, 7:55 PM
Sławek Śpiewak
Sławek Śpiewak - avatar
+ 1
yeah that helped and I also got some help from an online converter. That would be a tedious task to calculate manually... thanks to Python. have a great time ahead. Regards, Adarsh
5th Jul 2016, 7:11 PM
Adarsh Namdev
Adarsh Namdev - avatar