You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
Required fields*
lang-py
str(bin(i))[2:](0.369s for 1000000ops) than"{0:b}".format(i)(0.721s for 1000000ops)str.format()is the wrong tool anyway, you would useformat(i, 'b')instead. Take into account that that also gives you padding and alignment options though;format(i, '016b')to format to a 16-bit zero-padded binary number. To do the same withbin()you'd have to add astr.zfill()call:bin(i)[2:].zfill(16)(no need to callstr()!).format()'s readability and flexibility (dynamic formatting is much harder withbin()) are great tradeoffs, don't optimise for performance unless you have to, until then optimise for maintainability.f"{37:b}".