在python中拆分函数,将句子中的单词分成列表

时间:2015-12-10 15:58:25

标签: python python-3.x split

Sentence = print("Hello, i am the 14 year old creator of this program")
MySentence = (Sentence.lower())

错误:

  

NoneType'对象没有属性' lower'

我希望它真的很基本,我只想让句子变成一个单词列表。

2 个答案:

答案 0 :(得分:1)

您假设print返回它正在打印的字符串,这不是真的,它返回None(因为返回类型为void)。你可以调用print来写入stdout的副作用,而不是返回值。

words = "Hello, i am the 14 year old creator of this program".lower().split()
print(words)

创建一个字符串列表,该字符串由字符串转换为小写的字符串中的空格分隔,然后打印列表的内容。

答案 1 :(得分:0)

print用于在控制台中打印结果。你可以尝试:

Sentence = "Hello, i am the 14 year old creator of this program"
MySentence = Sentence.lower()
print(MySentence)
相关问题