'''查找文件中某个字符串总共出现的次数'''
def findStr(str):
with open("filePath",'r') as f:
counts = 0
for line in f.readlines():
time = line.count(str)
counts += time
print("%s出现的次数:%d"%(str,counts))

findStr("str")

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案