Dumb python questions
Richard Jones
richard at bizarsoftware.com.au
Wed Aug 15 02:43:51 EDT 2001
On Wednesday 15 August 2001 15:59, 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 = 1 + 2j
>>> dir(a)
['conjugate', 'imag', 'real']
>>> a.imag
2.0
>>> a.real
1.0
See also the manual - the tutorial covers this in the Numbers section. The
library reference covers this in the Numbers section of the builtin types
section.
> 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
"type(value) == IntType"
"type(value) == type(1)"
See the manual under builtin functions, or the types module.
> 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.
This one I can't help you with as I can't recall what a "branch cut" is.
Richard
More information about the Python-list
mailing list