📅  最后修改于: 2022-03-11 14:47:12.077000             🧑  作者: Mango
my_string = "This is a long string that contain a string about a string"
# I want to replace the second "string" with "text"
nth = 2
my_string = my_string.replace("string", "text", nth)
my_string = my_string.replace("text", "string", nth-1)
# >>> my_string == "This is a long string that contain a text about string"