Dumb python questions
kosh
kosh at aesaeion.com
Wed Aug 15 02:23:07 CEST 2001
Paul Rubin wrote:
> 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.
>
>>> a = 3+4j
>>> dir(a)
['conjugate', 'imag', 'real']
>>> a.imag
4.0
>>> a.real
3.0
> 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
>
>>> import types
>>> a = 3
>>> isinstance(a, types.IntType)
1
>>> a = 3L
>>> isinstance(a, types.LongType)
1
>>> a = 3.0
>>> isinstance(a, types.FloatType)
1
>>> a = 3+2j
>>> isinstance(a, types.ComplexType)
1
> 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.
I am not sure what this question is asking so I will leave it to others to
answer.
More information about the Python-list
mailing list