小册名称:Python合辑4-130个字符串操作示例
Python计数字符串出现在给定字符串中
txt = "I love Canada, Canada is one of the most impressive countries in the world. Canada is a great country."x = txt.count("Canada")print(x)
txt = "I love Canada, Canada is one of the most impressive countries in the world. Canada is a great country."
x = txt.count("Canada")
print(x)
Output:
3