📌  相关文章
📜  您将在命令行上收到文件路径 P 和字符串 S.输出字符串 S 在文件 P 中出现的次数. - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:19.004000             🧑  作者: Mango

代码示例1
You will be passed a file path P and string S on the command line. Output the number of times the string S appears in the file P.

file = open(P, 'r')
ptext = file.read()
print(ptext.count(S))
file.close()