当前位置:  首页>> 技术小册>> Python合辑4-130个字符串操作示例

Python计数字符串出现在给定字符串中

  1. txt = "I love Canada, Canada is one of the most impressive countries in the world. Canada is a great country."
  2. x = txt.count("Canada")
  3. print(x)

Output:

  1. 3