PHP的Python中的str_replace?

时间:2018-02-07 04:30:03

标签: php python

Python的str_replace函数是否有类似的东西?

我正在寻找能够做到这一点的事情:

string_world = str_replace('Place', "World", "Hello World!")
print (string_world)

Hello Peter!

特别要取代我的

str_replace('mp', ' ', $_GET['FML'])

2 个答案:

答案 0 :(得分:2)

您可以在字符串上使用.replace()

str = "Hello World!"
print str.replace("World", "Place")

答案 1 :(得分:1)

当你打印时第一件事"你好彼得"你应该写string_world = str_replace("World", "Peter", "Hello World!")请检查你的问题。

对于Python中的String替换,请使用以下内容:

str = "Hello World"
print str.replace("World", "Peter") 
print str.replace("World", "Peter", 1) #Parameters: str.replace(find, replace, count)
相关问题