Menu Close

Python bin() Function

In this python built-in functions tutorial, we are going to learn all about the Python bin function to get the binary value of a specified integer.
In the previous python tutorial, we have seen Python any function along with examples.

What is Python bin() Function?

Python bin function is a built-in function that is used to find the binary value of a specified integer. The result of the bin function in python will always start with the prefix 0b.

Syntax

The syntax of bin function in python is:-

bin(n)

Parameter Value

bin function in Python accepts only one parameter that is an integer.

  • n:– Required An Integer.

Return Value

The return value of the bin function in python is a binary value.

Python bin function example

Here we will use the bin method in python to get the binary value of a given integer.

Example 1:

Find the binary value of 20 using the bin function.

x = 20
print(bin(x))

Output will be:- 0b10100

Example 2:

The binary value of 50.

result = bin(50)
print(result)

The output will be:- ob110010

Conclusion

In this tutorial, you have learned the bin method in python to find the binary value of a given integer. This is the best python built-in function for getting binary values.

If this article helped you, please keep visiting for further python built-in functions tutorials.

For more information:- Click Here

Previous Article
Next Article

Related Posts