Site icon i2tutorials

Bin() method in Python Built in Function

Bin() method in Python Built in Function

 

bin method in built function returns the binary version of the number as the output.Only numbers are the values in this method.

 

Syntax

bin(x)

 

Parameters:

It has only single parameter

 

Example-1:

 

Using integer

x = bin(62)
print(x)

 

Output :

 

Example-2:

 

Using negative value

x = bin(-98)
print(x)

 

Output:

 

Example-3:

 

Using # symbol

x= format(18, '#b')
print (x)

 

Output:

 

Example-4:

 

Using without # symbol

x= format(17, 'b')
print (x)

 

Output:

 

Example-5:

 

Using  : and # symbols

x= f'{13:#b}'
print(x)

 

Output:

 

Example-6:

 

Using without # symbol

x= f'{14:b}'
print (x)

 

Output:

Exit mobile version