Python bin Function with Examples

The bin function in Python is utilized to provide the binary representation of a given integer. The output consistently begins with the prefix 0b.

Python bin Function Syntax

It has the following syntax:

Example

bin(n)

Parameters

  • n: It represents an integer.
  • Return

It provides the binary format of a given integer.

Python bin Function Example 1

To illustrate the functionality of the Python bin method, let's consider an example.

Example

x =  10

y =  bin(x)

print (y)

Output:

Output

0b1010

Note: The result will always be prefixed with '0b'.

Input Required

This code uses input(). Please provide values below: