Python - int()

The int() function returns integer object from a float or a string containing digits.


To convert octal number to integer in decimal number system


Second parameter to the function is the base of number system. Here �12� is string representation of octal number that is equivalent to 10 (Ten) in decimal number system (with base=10).

Similarly, Hexadecimal number (with base=16) is converted to decimal number.


Remember that string is converted to integer only if it is made of digits only. For string containing non-digit characters, int() function encounters following error:

ValueError: invalid literal for int() with base 10: 'aaa'

Learn Python using coding questions with answers.

Python Questions & Answers

Want to check how much you know Python?

Start Python Skill Test