with open(r"d:\test\test.txt") as f: # print(f.readline() == "abc") # false # readline只能用一次 print(f.read().strip() == "abc") # true