Function Details: bin

Description


Returns the binary representation of an integer.


Extended Description


The bin() function converts an integer number to a binary string prefixed with '0b'. This function provides a simple way to see the binary representation of a number. If the argument is not an integer, it must define an __index__() method that returns an integer.


Exceptions


  • TypeError: If the argument does not have an __index__() method that returns an integer

Read More about bin from Python Documentation

Function Signature


bin(x: int) -> str

Module: builtins

Parameters


This function takes one parameter: x (an integer). If x is not an integer, it should be an object that implements __index__() method returning an integer.


Parameter List


  • x: int

Return


Returns a string starting with '0b', which is the binary representation of the input integer.


Return Type


str

Output

Explanation

This example shows how bin() works with positive, negative, and zero integers.