8.3 文件读取的课后练习讲解
练习
统计文本内,某单词出现的次数
f = open("8.3.txt", "r", encoding="UTF-8") txt = f.read() num = txt.count("snow") print(num) f.close()I am snow i love snow nickname is lonelysnow输出结果:
3
Last updated
Was this helpful?
统计文本内,某单词出现的次数
f = open("8.3.txt", "r", encoding="UTF-8")
txt = f.read()
num = txt.count("snow")
print(num)
f.close()I am snow
i love snow
nickname is lonelysnow输出结果:
3
Last updated
Was this helpful?
Was this helpful?