[Tutor] How to print complex numbers without enclosing parentheses
srilyk at gmail.com
Fri Sep 19 12:46:16 CEST 2008
On Fri, Sep 19, 2008 at 4:26 AM, Stephen McInerney
<spmcinerney at hotmail.com>wrote:
> Why does the complex.__str__() method on complex numbers add the enclosing
> It's unwanted, and it also makes them look like a tuple (other than the
> trailing comma).
> How can I get rid of it, other than the clunky:
> >>> print d
> >>> print repr(d)[1:-1]
> How can I change complex.__str__() ?
>>> def printComp(comp):
... comp = str(comp)
... comp = comp.strip(')')
... comp = comp.strip('(')
... print comp
That's the best I could come up with...
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor