在txt文件中输入
Zoom
Zoom
Vinteo
YouTube
VK
Zoom
读取文件并统计输出Zoom的个数
只是输出个数?
代码如下:
01.txt
Zoom
Zoom
Vinteo
YouTube
VK
Zoom
main.py
input_file = '01.txt'
word = 'Zoom'
count = 0
with open(input_file, "r") as fr:
lines = fr.readlines()
for line in lines:
if word == line.replace("\n", ""):
count += 1
print("{word}的个数为:{count}".format(word=word, count=count))
输出为:
Zoom的个数为:3
如有问题及时沟通