Fix Python – Why does Python 3 allow “00” as a literal for 0 but not allow “01” as a literal for 1?

Why does Python 3 allow “00” as a literal for 0 but not allow “01” as a literal for 1? Is there a good reason? This inconsistency baffles me. (And we’re talking about Python 3, which purposely broke backward compatibility in order to achieve goals like consistency.)
For example:
>>> from datetime import time
>>> time(16, 00)
datetime.time(16, 0)
>….

Fix Python – Why can’t Python’s raw string literals end with a single backslash?

Technically, any odd number of backslashes, as described in the documentation.
>>> r’\’
File ““, line 1
r’\’
^
SyntaxError: EOL while scanning string literal
>>> r’\\’
‘\\\\’
>>> r’\\\’
File ““, line 1
r’\\\’
^
SyntaxError: EOL while scanning string literal

It seems like the parser could just treat backsl….

Fix Python – How do you express binary literals in Python?

How do you express an integer as a binary number with Python literals?
I was easily able to find the answer for hex:
>>> 0x12AF
4783
>>> 0x100
256

and octal:
>>> 01267
695
>>> 0100
64

How do you use literals to express binary in Python?

Summary of Answers

Python 2.5 and earlier: can express binary using int(‘01010101111’,2) but not with a lite….

Fix Python – Why is [] faster than list()?

I recently compared the processing speeds of [] and list() and was surprised to discover that [] runs more than three times faster than list(). I ran the same test with {} and dict() and the results were practically identical: [] and {} both took around 0.128sec / million cycles, while list() and dict() took roughly 0.428sec / million cycles each…..