convert a number from other base to integer

I have been using the int() function for converting string representation of a number to it's numeric value. For example: number = int('1050')

But today I just come to know that there is an optional second argument in the int function. It will help you convert any number from base 2 to 36 into base 10. Few examples are given below:
>>> int('xyz', 36)
44027
>>> int('ff', 16)
255
>>> int('FF', 16)
255
>>> int('f', 16)
15
>>> int('10', 2)
2
>>> int('10')
10
>>> int('10', 10)
10

Python is simple!

Comments

Popular posts from this blog

Strip HTML tags using Python

lambda magic to find prime numbers

Convert text to ASCII and ASCII to text - Python code