【发布时间】:2011-01-29 21:02:30
【问题描述】:
我在 Python 中有这段代码
inputted = input("Enter in something: ")
print("Input is {0}, including the return".format(inputted))
输出
Enter in something: something
Input is something
, including the return
我不确定发生了什么;如果我使用不依赖于用户输入的变量,则在使用变量格式化后我不会得到换行符。我怀疑当我点击返回时 Python 可能会将换行符作为输入。
如何使输入不包含任何换行符,以便我可以将其与其他字符串/字符进行比较? (例如something == 'a')
【问题讨论】:
-
您使用的是哪个操作系统/Python 版本?我无法在 Win XP 上使用 Python 3.1.1 重现此问题。
-
@AndiDog:Python 3.1.1,带有 Eclipse 的 Windows 7
-
题外话,但是如果打印调用以“return”结尾,那么输出不应该以“return”结尾,而不是“the newline”。
-
@None-whoopw!你是对的:)
标签: python input newline user-input