How to Use bin() Function in PythonPython Basics


The bin() method converts a given integer into an equivalent binary string.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

print(bin(10))
print(bin(20))

Output:

0b1010
0b10100

Syntax

bin(num)

Parameters

Name Description
num An integer whose binary equivalent is to be calculated

Return Value

It returns the binary string which is equivalent to the given integer.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us