我目前开始使用python 2中的python 3.在Python 2中,字符串类型转换可以使用int()函数轻松完成,但我在Py3.5.3中遇到问题
current = input("Enter the Current price: ")
int(current)
print (type(current))
c = current - 24
Run Code Online (Sandbox Code Playgroud)
Class str即使在类型转换功能之后,电流仍然显示为.
错误是 TypeError: unsupported operand type(s) for -: 'str' and 'int'
我知道这只是一个小错误,但我在网上查看的例子都使用了我使用的int函数.这可能是什么问题
您没有保存返回值int(current),这是整数表示.尝试
current = int(current)
Run Code Online (Sandbox Code Playgroud)
应该这样做.