Dumb python questions

Paul Rubin phr-n2001 at nightsong.com
Wed Aug 15 01:59:05 EDT 2001


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