Python bin() function

Published February 15, 2022

Bin() is a built-in Python function that accepts an integer and returns the binary representation in string format. Basically, this method transforms and returns a specified number into an equivalent binary string.

Syntax

The syntax of the bin() function  is:

bin(number)

where, number, is the integer value whose binary string is to be returned

Example

This example converts a number into a binary using the bin() function

num = 100

#convert number to binary

a = bin(num)

# display binary number

print(a)

Output

If you run  the above code, the following will be output.

Python bin function

 

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

280 Views