简体   繁体   中英

How can I comparing input() and .readline()?

Both of strings from userInput and fcon matches, it is still unable to print the "matched" message.

I have tried comparing two strings from input() it work.

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")


Try it Please,

userInput = input("First String: ")

with open("file1.txt", "r") as nameDb:
    fcon = nameDb.readline()

if userInput == fcon:
    print("Matched")
else:
    print("NO match")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM