案例取出数据统计个数
num = 0
with open("D:/word.txt", "r", encoding="UTF-8") as f:
for x in f:
word = x.strip().split(" ") #去掉首位空格,通过空格来分割元素
for words in word:
if words == "itheima":
num +=1
print(num)
with open("D:/word.txt", "r", encoding="UTF-8") as f:
num = f.read()
num1 = num.count("itheima")
print(f"出现次数{num1}")