这是我的任务
journey = """Just a small tone girl
Leaving in a lonely whirl
She took the midnight tray going anywhere
Just a seedy boy
Bored and raised in South Detroit or something
He took the midnight tray going anywhere"""
真恶心。好的,对于这个练习,您的工作是使用Python的string replace方法来修复这个字符串,并将新版本打印到控制台。你知道吗
我就是这么做的
journey = """ just a small tone girl
Leaving in a lonely whirl
she took a midnight tray going anywhere
Just a seedy boy
bored and raised in south detroit or something
He took the midnight tray going anywhere"""
journeyEdit = journey.replace("tone" ,
"town").replace("tray","train").replace("seedy","city").replace("Leaving",
"living").replace("bored","born").replace("whirl","world").replace("or
something", " ")
print (journeyEdit)
可能比你给的路要长;-)。你知道吗
如How to replace multiple substrings of a string?所示:
下面是一个从文本中替换单词的示例方法。您可以使用python re包。你知道吗
请查找以下代码以供您参考。你知道吗
相关问题 更多 >
编程相关推荐