Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中的Split函数,用于将句子中的单词分隔成一个列表_Python_Python 3.x_Split - Fatal编程技术网

python中的Split函数,用于将句子中的单词分隔成一个列表

python中的Split函数,用于将句子中的单词分隔成一个列表,python,python-3.x,split,Python,Python 3.x,Split,错误: “非类型”对象没有属性“低” 我希望它是非常基本的,我只希望这个句子变成一个单词列表。您假设print返回它正在打印的字符串,这不是真的,它不返回任何字符串(因为返回类型是空的)。调用print是因为写入stdout的副作用,而不是为了返回值 Sentence = print("Hello, i am the 14 year old creator of this program") MySentence = (Sentence.lower()) 从文字字符串转换为小写的字符串中创建一

错误:

“非类型”对象没有属性“低”


我希望它是非常基本的,我只希望这个句子变成一个单词列表。

您假设print返回它正在打印的字符串,这不是真的,它不返回任何字符串(因为返回类型是空的)。调用print是因为写入stdout的副作用,而不是为了返回值

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

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

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

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

非常感谢你。。。但我也需要知道如何分割句子
Sentence = "Hello, i am the 14 year old creator of this program"
MySentence = Sentence.lower()
print(MySentence)