我不确定在第2行的下面两个场景中读取文件的方式是否存在差异.第一个场景'r'在open命令中有一个,而第二个场景没有.两者都输出相同的结果.这些只是获得相同结果的不同方法吗?
场景1:
def readit(filename, astr):
infile = open(filename, 'r')
content = infile.read()
infile.close()
return content.count(astr)
print(readit("payroll.txt","Sue"))
Run Code Online (Sandbox Code Playgroud)
场景2:
def readit(filename, astr):
infile = open(filename)
content = infile.read()
infile.close()
return content.count(astr)
print(readit("payroll.txt","Sue"))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
54 次 |
| 最近记录: |