how to improve this simple block of code

Peter Otten __peter__ at web.de
Wed Jan 11 10:40:51 EST 2006


Mike Meyer wrote:

> "py" <codecraig at gmail.com> writes:
>> Say I have...
>> x = "132.00"
>> but I'd like to display it to be "132" ...dropping the trailing
>> zeros...I currently try this
> 
> The two-strip solution is cleaner, but:
> 
>> if x.endswith("0"):
>>     x = x[:len(x)-1]
>       x = x[:-1]
> or
>       del x[-1]
> 
> both improve that one statement.

>>> del "it's tempting not to try"[-1]
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: object doesn't support item deletion

Just-pointing-out-what-does-not-work-ly yours

Peter



More information about the Python-list mailing list