小编Rai*_*ers的帖子

在Python中删除尾随零

我需要找到一种方法来转换python中的以下字符串:

0.000       => 0
0           => 0
123.45000   => 123.45
0000        => 0
123.4506780 => 123.450678
Run Code Online (Sandbox Code Playgroud)

等等.我尝试了.rstrip('0').rstrip('.'),但如果输入为0或00则不起作用.

有任何想法吗?谢谢!

python string zero

24
推荐指数
3
解决办法
3万
查看次数

标签 统计

python ×1

string ×1

zero ×1