Python函数,用于在传递sentense和word时将单词从sentense改为大写
我试图创建一个单行函数,将单词从句子改为大写。请建议Python函数,用于在传递sentense和word时将单词从sentense改为大写,python,function,Python,Function,我试图创建一个单行函数,将单词从句子改为大写。请建议 def highlight_word(sentence, word): return(___) 这应该符合您的要求,使用string.replace()和string.upper() 代码: def highlight_word(sentence, word): return sentence.replace(word, word.upper()) >>> highlight_word('I like P
def highlight_word(sentence, word):
return(___)
这应该符合您的要求,使用
string.replace()
和string.upper()
代码:
def highlight_word(sentence, word):
return sentence.replace(word, word.upper())
>>> highlight_word('I like Python', 'like')
'I LIKE Python'
用法:
def highlight_word(sentence, word):
return sentence.replace(word, word.upper())
>>> highlight_word('I like Python', 'like')
'I LIKE Python'
欢迎来到StackOverflow。因此,它不是一个代码编写服务。请提供一些示例输入、所需输出以及您遇到的任何问题。只需注意替换词作为另一个词的一部分出现。