Python int() function

Published February 16, 2022

The int() method in Python returns the numeric integer equivalent of a specified expression. An integer can be returned from a given object using the Python int() method or converted from a specified base to decimal using the int().

Syntax
 

Int(string, base)

Where:
String comprises of 0’s and 1’s
Base refers to the integer value which represents  the base of the number

Example
 

x = '10000'
print("10000 with base 2 = ", int(x, 2))
print("10000 with base 4 = ", int(x, 4))
print("10000 with base 8 = ", int(x, 8))
print("10000 with base 16 = ", int(x, 16))


Output

10000 with base 2 =  16
10000 with base 4 =  256
10000 with base 8 =  4096
10000 with base 16 =  65536

 

 

Download Source code

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

236 Views