<jupyter_start><jupyter_text>All the IPython Notebooks in this lecture series by Dr. <NAME> are available @ **[GitHub](https://github.com/milaan9/04_Python_Functions/tree/main/002_Python_Functions_Built_in)**  Python `bin()`The **`bin()`** method converts and returns the binary equivalent string of a given integer. If the parameter isn't an integer, it has to implement **`__index__()`** method to return an integer.**Syntax**:```pythonbin(num)```  `bin()` Parameters**`bin()`** method takes a single parameter:* **num** - an integer number whose binary equivalent is to be calculated.If not an integer, should implement **`__index__()`** method to return an integer.  Return Value from `bin()`**`bin()`** method returns the binary string equivalent to the given integer.If not specified an integer, it raises a **`TypeError`** exception highlighting the type cannot be interpreted as an integer.<jupyter_code># Example 1: Convert integer to binary using bin()
number = 5
print('The binary equivalent of 5 is:', bin(number))<jupyter_output>The binary equivalent of 5 is: 0b101<jupyter_text>The prefix **`0b`** represents that the result is a binary string.<jupyter_code># Example 2: Convert an object to binary implementing __index__() method

class Quantity:
    apple = 1
    orange = 2
    grapes = 2
    
    def __index__(self):
        return self.apple + self.orange + self.grapes
        
print('The binary equivalent of quantity is:', bin(Quantity()))<jupyter_output>The binary equivalent of quantity is: 0b101
{'fraction_non_alphanumeric': 0.11242603550295859, 'fraction_numerical': 0.015121630506245891, 'mean_word_length': 5.186991869918699, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '286388', 'license': 'MIT', 'n_tokens_mistral': 450, 'n_tokens_neox': 414, 'n_words': 177, 'path': '002_Python_Functions_Built_in/005_Python_bin().ipynb', 'repo_name': 'ATrain951/01.python_function-milaan9', 'size': '1527'}