Dumb python questions
Franz GEIGER
fgeiger at datec.at
Wed Aug 15 08:56:57 CEST 2001
Hi Paul,
from an interactive session I got:
ActivePython 2.1.1, build 212 (ActiveState)
Python 2.1.1 (#20, Jul 26 2001, 11:38:51) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> z=complex(1,2)
>>> z
(1+2j)
>>> z.real
1.0
>>> z.imag
2.0
>>>
>>>
>>>
>>> from types import *
>>> print type(1) == IntType
1
>>> print type(1L) == IntType
0
>>> print type(1L) == LongType
1
>>>
Cheers
Franz
"Paul Rubin" <phr-n2001 at nightsong.com> wrote in message
news:7xd75xlv86.fsf at ruckus.brouhaha.com...
> I just started playing with python and haven't been able to figure
> out the following things from the docs I've found:
>
> 1) Suppose I have a complex number like a = 3+4j. How do I get the
> real and imaginary parts separately? I guess I could say
> x = (a + a.conjugate())/2
> y = (a - a.conjugate())/2
> but I can't take this language seriously if that's what the designers
intended.
>
> 2) Is there a way I can tell if a value is of an integer type? That is,
> I want to write a function is_int(x) so that
> is_int(3) = 1 # 3 is an integer type
> is_int(3L) = 1 # 3L is an integer type
> is_int(3.0) = 0 # 3.0 is float type
> is_int(3+2j) = 0 # 3+2j is complex type
>
> 3) Are the complex math functions specified to have any particular
> branch cuts? If they're unspecified, what happens in the actual cmath
> implementation? If they're unspecified, I'd like to propose that the
> Scheme/Common Lisp conventions be adopted in a future version.
>
More information about the Python-list
mailing list