int() function in Python and Python3 converts a number in given base to decimal.
string : consists of 1's and 0's base : (integer value) base of the number.
Returns an integer value, which is equivalent of binary string in the given base.
TypeError : Returns TypeError when any data type other than string or integer is passed in its equivalent position.
Code #1 :
int('187') + 13 = 200 int('100') with base 2 = 4 int('100') with base 4 = 16 int('100') with base 8 = 64 int('100') with base 16 = 256
Code #2 :
Decimal equivalent of binary 111 is 7 Octal equivalent of binary 101 is 65
Code #3 : Program to demonstrate the TypeError.
Traceback (most recent call last): File "/home/d87cec4c0c33aad3bb6187858b40b734.py", line 8, in decimal = int(binaryString, 2) TypeError: int() can't convert non-string with explicit base
It is used in all the standard conversions. For example conversion of binary to decimal, binary to octal, binary to hexadecimal.
- Python - Call function from another function
- Python | hex() function
- Help function in Python
- Python | dir() function
- Python | oct() function
- Python | now() function
- Python | cmp() function
- Python tell() function
- Python map() function
- id() function in Python
- sum() function in Python
- Python | How to get function name ?
- ord() function in Python
- isdisjoint() function in Python
- Union() function in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.