小编huh*_*ulu的帖子

python3:如何添加字符串中的小数

我是初学者,我想在字符串中添加小数 s

 totalsum=0
 s='1.23 2.4 3.123'
 for a in s:
    totalsum=totalsum+float(a)
 print (totalsum)
Run Code Online (Sandbox Code Playgroud)

但是当我试着说

ValueError: could not convert string to float: '.'
Run Code Online (Sandbox Code Playgroud)

如何添加这三位小数?

python string decimal python-3.x

5
推荐指数
1
解决办法
38
查看次数

标签 统计

decimal ×1

python ×1

python-3.x ×1

string ×1