小编Ric*_*dad的帖子

根据列表中的匹配单词将单词大写

通过“Coursera Python”课程,我遇到了很多麻烦。

highlight_word函数将句子中的给定单词更改为其大写版本。例如,highlight_word("Have a nice day", "nice")返回"Have a NICE day". 我需要帮助在一行中重写这个函数吗?

def highlight_word(sentence, word):
    return(___)

print(highlight_word("Have a nice day", "nice"))
print(highlight_word("Shhh, don't be so loud!", "loud"))
print(highlight_word("Automating with Python is fun", "fun"))
Run Code Online (Sandbox Code Playgroud)

我想我可以在更大的语句中做到这一点,但有没有人知道如何在一行中正确返回它?我猜这将涉及列表理解。

python list-comprehension list uppercase

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

list ×1

list-comprehension ×1

python ×1

uppercase ×1