![](/img/trans.png)
[英]How can I get interactive Python to avoid using readline while allowing utf-8 input?
[英]How can I comparing input() and .readline()?
userInput
和fcon
中的字符串fcon
匹配,但仍然无法打印“匹配”消息。
我试过比较input()
两个字符串,它起作用了。
userInput = input("First String")
with open("file1", mode ="r") as nameDb:
fcon = nameDb.readline()
print(type(fcon),fcon)
print(type(userInput), userInput)
if userInput is fcon:
print("Matched")
else:
print("No match")
试试吧,
userInput = input("First String: ")
with open("file1.txt", "r") as nameDb:
fcon = nameDb.readline()
if userInput == fcon:
print("Matched")
else:
print("NO match")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.