with open .read() re.findall用法

    xiaoxiao2025-05-04  10

    import re with open("/Users/zxxl/PycharmProjects/fishc/countre", "r") as file: content = file.read() print(re.findall("love", content)) print(len(re.findall("love", content)))

    1)打开一文件 with open() as file: 2)读取出内容存给一变量 file.read() 3)从全部内容中找到某字符串 import re re.findall(“查找内容”, file.read) 4)统计该字符串出现的次数 len(list)

    最新回复(0)