我已经搜索了一些答案,但似乎都没有用。
下面是一个示例,但代码不起作用并给出错误。我正在使用 Python 2.7。
operationTwo = 91239
operationTwo = operationTwo[:-1]
print(operationTwo)
原文由 user7513134 发布,翻译遵循 CC BY-SA 4.0 许可协议
我已经搜索了一些答案,但似乎都没有用。
下面是一个示例,但代码不起作用并给出错误。我正在使用 Python 2.7。
operationTwo = 91239
operationTwo = operationTwo[:-1]
print(operationTwo)
原文由 user7513134 发布,翻译遵循 CC BY-SA 4.0 许可协议
2 回答5.1k 阅读✓ 已解决
2 回答1.1k 阅读✓ 已解决
4 回答974 阅读✓ 已解决
3 回答1.1k 阅读✓ 已解决
3 回答1.2k 阅读✓ 已解决
1 回答1.7k 阅读✓ 已解决
1 回答1.2k 阅读✓ 已解决
您找到的代码是
slicing
,但不能用于integers
。如果要使用它,可以将数字转换为str
进行切片,然后将其转换回int
。这不是最佳做法,但可以按以下方式完成:然而,我会选择
integer
部门,例如: