【发布时间】:2018-01-22 18:40:29
【问题描述】:
我是python新手,所以这个问题可能有一个简单的答案,但我看了看,一无所获。
我想定义一个函数,当它被输入时:“function(abcdefg123, fg1, " ")” 返回是这样的:“abcde 23”。我想应该是这样的:
def function(something, what_to_deleat, what_to_substitute):
if str(what_to_deleat) in str(something):
return ## Code that replaces "what_to_deleat" with "what_to_substitute" within "something"
else:
return something
如果输入了 'function("25.0", ".0", "")',实际应用程序(以及我想要使用的应用程序)会将 25.0 转换为 25。
【问题讨论】:
-
string.replace() 方法可以。这里pythoncentral.io/…
标签: python