0

Assume:

>> a = 128
>> dir(a)
['__abs__', ..., '__xor__', 'bit_length', 'conjugate', 'denominator', 'imag', 'numerator', 'real']

The instruction:

>> dir(128)
['__abs__', ..., '__xor__', 'bit_length', 'conjugate', 'denominator', 'imag', 'numerator', 'real']

returns the same exactly previous result.

I can't explain why

>> a.bit_length()
8

works correctly but

>> 128.bit_length()
  File "<stdin>", line 1
    128.bit_length()
                 ^
SyntaxError: invalid syntax

throws a SyntaxError.

The second 128 is "parsed" a new int object should be created in memory. Why it can't access the method?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
c.bear
  • 1,197
  • 8
  • 21

0 Answers0