写了一小段Python代码,想要实现键盘终止程序。代码如下:
while True:
profit = input("input:")
if profit == "quit":
break
print('Done')
发现并不如愿。将第二行中的函数input修改为raw_input后,则可实现循环终止。
raw_input( ): raw_input将输入作为字符串。
intput( ): input将输入转为Python表达式。
PS: Python 3.x版本不存在上述问题。
参考:
http://zhidao.baidu.com/link?url=a62XDI93gjJXhfW3WwgJVZjBx7WDqnoTXURQNWuWh1uKfOAuUX0ZQ7-XGQtlls_FN4ZySZmwHZJEAK-xP32JRq
http://stackoverflow.com/questions/4915361/whats-the-difference-between-raw-input-and-input-in-python3-x