[Python-Dev] Int literals and method calls

Gerrit gerrit at nl.linux.org
Mon Nov 15 10:54:01 CET 2004


"Martin v. Löwis" wrote:
> Michael Walter wrote:
> >It's confusing/inconsistent.
> 
> That is not true. It might be confusing, but it is not inconsistent.

It works for complex numbers:

>>> 1j.imag
1.0

...in a rather surprising way:

>>> 3+4j.real
3.0
>>> f() + 5j.real
42.0

I would have expected it to be 0.0, because I would have expected the
'.' to have precedence over the '+', but it hasn't. apparantly.

Or has it?
>>> 3+4j.__class__
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: unsupported operand type(s) for +: 'int' and 'type'

I would call it inconsistent:

    3+4j.real means (3+4j).real
    3+4j.__class__ means 4+(4j).__class__

Enough ignorance from my side? :-)

regards,
Gerrit Holl.

-- 
Weather in Twenthe, Netherlands 15/11 09:25:
	5.0°C Few clouds overcast wind 3.1 m/s SSW (57 m above NAP)
-- 
In the councils of government, we must guard against the acquisition of
unwarranted influence, whether sought or unsought, by the
military-industrial complex. The potential for the disastrous rise of
misplaced power exists and will persist.
    -Dwight David Eisenhower, January 17, 1961


More information about the Python-Dev mailing list