I have a small bit of code in Python 3 -
'{:08b}' .format(i)
that gives an error in Python 2.x. Does anyone know the equivalent?
Your original code actually works in Python 2.7. For Python 2.6, you need to introduce a reference to your format
argument - either an index (0
):
'{0:08b}'.format(i)
or a name:
'{x:08b}'.format(x=i) # or:
'{i:08b}'.format(i=i) # or even:
'{_:08b}'.format(_=i) # (since you don't care about the name)
Strangely enough, this particular quirk doesn't seem to be mentioned in the documentation about string formatting :(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With