【问题标题】:Strings: replacing a word in a string [duplicate]字符串:替换字符串中的单词[重复]
【发布时间】:2020-04-28 04:40:14
【问题描述】:

给定字符串“To dance or not to dance”,让程序将所有出现的“dance”一词替换为“be”。

我的尝试,但有错误

    word = "To dance or not to dance"
    replaceWords = str_replace("dance","be", word)
    print (replaceWords)

【问题讨论】:

标签: python string


【解决方案1】:

我认为这可行。

word = word.replace("dance","be")

【讨论】:

    【解决方案2】:
    new_word=word.replace("dance", "be")
    

    【讨论】:

      猜你喜欢
      • 2020-11-09
      • 2017-12-20
      • 1970-01-01
      • 2018-08-05
      • 1970-01-01
      • 1970-01-01
      • 2011-10-10
      • 2021-08-01
      • 2015-07-03
      相关资源
      最近更新 更多