小编Sam*_*man的帖子

堆叠内联 For plus If else

我写了一行应该总结除 0 之外的字符串的所有数字。在零上它应该加上 5。

怎么了

s="123450"
o=sum([int(x) for x in s if int(x) != 0 else 5])
Run Code Online (Sandbox Code Playgroud)

它给出了语法错误,但是

s="123450"
o=sum([int(x) for x in s if int(x) != 0])
Run Code Online (Sandbox Code Playgroud)

工作正常。

python python-3.x

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

标签 统计

python ×1

python-3.x ×1