in Python 2.7, why do I have to enclose an `int` in brackets when I want to call a method on it?

python

Solution

That's a parser idiosyncrasy.

When Python sees the `.`, it starts looking for decimals. Your decimal is a `b`, so that fails.

If you do `(5).bit_length()`, then Python will first parse what's between the `()`, and then look for the `bit_length` method.

If you try:

5..zzz

You'll get the `AttributeError` you expect. This won't work for integers though: `5.` is a float.

Problem

in Python 2.7, why do I have to enclose an `int` in brackets when I want to call a method on it? ``` >>> 5.bit_length() SyntaxError: invalid syntax >>> (5).bit_length() 3 ```

Original source