字符串:替换字符串中的单词

时间:2020-04-27 20:33:38

标签: python string

给出字符串“跳舞还是不跳舞”,让程序将“ dance”一词的所有出现替换为“ be”。

我的尝试但是有错误

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

2 个答案:

答案 0 :(得分:1)

我认为这可行。

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

答案 1 :(得分:1)

x <- c(NA, 5, 10)
rng <- range(x, na.rm = TRUE, finite = TRUE)
x -rng[1]
[1] NA  0  5
相关问题