在Python中,我要替换<;短语>;母牛跳过了月亮</短语>;与<;短语>;奶牛跳过月亮</短语>;
在Python中,我想用在Python中,我要替换<;短语>;母牛跳过了月亮</短语>;与<;短语>;奶牛跳过月亮</短语>;,python,string,replace,Python,String,Replace,在Python中,我想用奶牛跳过月亮来替换奶牛跳过月亮 因此,只有在和中,空格应替换为u,这是一个下划线 不应更改所有其他位置请使用替换方法执行任务 msg1 = "the cow jumped over the moon" print(str(msg1).replace(" ","_")) 输出: the_cow_jumped_over_the_moon 这回答了你的问题吗?
奶牛跳过月亮来替换奶牛跳过月亮
因此,只有在
和
中,空格应替换为u,这是一个下划线
不应更改所有其他位置请使用替换方法执行任务
msg1 = "the cow jumped over the moon"
print(str(msg1).replace(" ","_"))
输出:
the_cow_jumped_over_the_moon
这回答了你的问题吗?