python - 无法将字符串转换为 int

标签 python python-3.5

我目前从 python 2 开始使用 python 3。在 Python 2 中,可以使用 int() 函数轻松完成字符串类型转换,但我在 Py3.5.3 中遇到问题

current = input("Enter the Current price: ")
int(current)
print (type(current))
c = current - 24

即使在类型转换函数之后,当前仍然显示为Class str

错误是TypeError:不支持的操作数类型 -:“str”和“int”

我知道这只是一个小错误,但我在网上查找的示例都像我一样使用 int 函数。这可能是什么问题

最佳答案

您没有保存 int(current) 的返回值,它是整数表示形式。尝试一下

current = int(current)

应该可以了。

关于python - 无法将字符串转换为 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42298198/

相关文章:

Python3 Selenium在弹出对话框中填写用户名和密码

python - 使用 while 循环来监听一个事件?

python - 数据不平衡的过度训练

python-sphinx - python 3 : Sphinx doesn't show type hints correctly

python - PyCharm 不检测解释器

python - 列表中的第 n 项到字典 python

python - 在列表python 3中查找子列表的索引

python - 使用 urllib2 从 URL 写入 PDF 文件

python - 使用 python 3.5 样式类型注释进行鸭子打字

python - PyQt:QDateComboBox setDate 使用字符串?