第10987题 单选
统计文件中Python单词出现次数的代码补全:空缺处应填入哪个选项

文件text.txt 的内容如下:

1 Python is a programming language. 2 Python is easy to learn.

以下程序统计单词"Python"在文件中出现的次数,Python后面是空格或行尾,且不跟标点,请补全代码中空缺部分:

count = 0
with open("text.txt", "r") as f:
  content = f.________ # 补全代码
  words = content.split()
  for word in words:
    if word == "Python":
      count += 1
print("Python出现次数:", count)
A

readlines()

B

read()

C

readline()

D

readlines

提交0次 正确率0.00%
答案解析