How to use the bin function in python
This article mainly introduces the relevant knowledge of how to use the bin function in python, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value, I believe you will have something to gain after reading this article on how to use the bin function in python. Let's take a look.
Analysis of specific examples:
Example 1
Print (bin (3)) print (type (bin (3)) print (bin (- 10)) print (type (bin (- 10)
The result returned by running the above code is:
0b11-0b1010
Example 2
Python code that converts a number to a binary string
# python code to convert number to binary# an example of bin () function in Python num1 = 55 # number (+ ve) num2 =-55 # number (- ve) # converting to binary bin_str = bin (num1) print ("Binary value of", num1, "is =", bin_str) bin_str = bin (num2) print ("Binary value of", num2, "is =", bin_str)
The output is as follows:
Binary value of 55 is = 0b110111Binary value of-55 is =-0b11011 this article on "how to use the bin function in python" ends here. Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to use the bin function in python". If you want to learn more knowledge, you are welcome to follow the industry information channel.