Built-in method to replace int/long with binary string

Asked 1 years ago, Updated 1 years ago, 63 views

I searched for a code that turns int/long into a binary string and found that only people defined it themselves, is there a method provided by Python itself?

I think this method will be supported directly

binary int python

2022-09-22 22:10

1 Answers

From Python 2.6, you can write bin().

print(bin(10))
print(bin(3333))

I understand that the simplest way to use less than 2.6 is to use the format.

print("{0:b}".format(10)) #1010


2022-09-22 22:10

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.