如何在Python中从字符串中搜索和删除短语?

2024-09-27 23:18:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我是一个新来的python,所以这个问题可能有一个简单的答案,但是我看了之后什么也没发现。你知道吗

我想定义一个函数,当它被输入时:“function(function(fegg123,fg1,”)”返回值是:“feg123”。我想应该是这样的:

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。你知道吗


Tags: to函数答案return定义functionwhatsomething

热门问题