【发布时间】:2023-02-16 22:01:48
【问题描述】:
我有这个字符串,我对 python 还很陌生,我只需要帮助就可以了。
def this_sentence(我的朋友去旅游了)
我希望输出看起来像这样 ['我的', '朋友', '去', 'ON', 'A', 'TOUR']
【问题讨论】:
标签: python string split uppercase
我有这个字符串,我对 python 还很陌生,我只需要帮助就可以了。
def this_sentence(我的朋友去旅游了)
我希望输出看起来像这样 ['我的', '朋友', '去', 'ON', 'A', 'TOUR']
【问题讨论】:
标签: python string split uppercase
您甚至不需要单独的函数,只需使用split() 和upper():
split_sentence = [word.upper() for word in sentence.split()]
【讨论】:
您可以使用 upper() 将所有字符设为大写,然后使用 split() 在每个空格处拆分单词。
def this_sentence(句子): 返回 sentence.upper().split()
【讨论】: