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

在 Python 中使用 string.replace()

  1. a = "This is the island of istanbul"
  2. print (a.replace("is" , "was", 1))
  3. print (a.replace("is" , "was", 2))
  4. print (a.replace("is" , "was"))

Output:

  1. Thwas is the island of istanbul
  2. Thwas was the island of istanbul
  3. Thwas was the wasland of wastanbul