'complex' function with string argument.

wxjmfauth at gmail.com wxjmfauth at gmail.com
Wed Mar 19 15:35:06 CET 2014


Le mercredi 19 mars 2014 12:04:06 UTC+1, Skip Montanaro a écrit :
> On Wed, Mar 19, 2014 at 5:33 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> 
> > When is it ever useful though?
> 
> 
> 
> About as often as int(0), float(0), or float(0.0) which all work as
> 
> expected, though probably don't turn up in a lot of code.
> 
> 
> 
> Skip

Your comment is equivalent to this:

>>> complex(1+2.0j)
(1+2j)
>>> complex(0+0.0j)
0j

Both, the constructor and the docstring, are not so clean.

What to say about the __repr__ ? Are not a and b
supposed to be floats? (elements of R)

>>> 0
0
>>> 0.0
0.0
>>> 0j
0j
>>> 1.0 + 2.0j
(1+2j)
>>> 1.
1.0
>>> 1
1
>>> (1 + 2.0j).real
1.0
>>> type((1 + 2.0j).real)
<class 'float'>

jmf




More information about the Python-list mailing list