I can invoke methods on numbers only when I bind them to a name:
>>> a = 5
>>> a.bit_length()
3
I can invoke methods on string literals:
>>> 'Hello World'.lower()
'hello world'
But I cannot invoke methods on numeric literals:
>>> 5.bit_length()
This raises a SyntaxError
. Is there a practical reason for that, or is it historic?
Edit Just found this related question that shows workarounds (that have already been suggested here as well). I guess this also answers the main question - with simple workarounds available, there probably wasn't enough benefit to making the grammar more complex (and harder to parse) to make this work.