Return a copy of the string with the leading and trailing characters removed. The chars argument is a string specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. The chars argument is not a prefix or suffix; rather, all combinations of its values are stripped
这是根据Docs
在这种情况下,您最好使用
round
:strip函数的工作方式与您期望的不同
例如,您的cmd是
'10000.0'.strip('.0')
:这意味着,您要求它删除字符串前面/后面与
"." or "0"
匹配的所有字符如果字符串中的字符与这些字符匹配,则会递归地将其删除。这就是为什么您将输出视为
1
例如,
11000.0
的输出将是11
替代方案:替换?还是int()函数?
int(float(10000.0))
=10000
'10000.0'.replace('.0', '')
='10000'
相关问题 更多 >
编程相关推荐