Mat*_*hew 1 python function list
我从函数输出的所有值都是在不同的行上分解的,我想把它变成一个列表.
The Score
Leon the Professional
Iron Man
Run Code Online (Sandbox Code Playgroud)
我想把它变成一个列表,如:
movies= ['The Score', 'Leon the Professional', 'Iron Man']
Run Code Online (Sandbox Code Playgroud)
我该怎么做呢?
假设您的输入是一个字符串.
>>> text = '''The Score
Leon the Professional
Iron Man'''
>>> text.splitlines()
['The Score', 'Leon the Professional', 'Iron Man']
Run Code Online (Sandbox Code Playgroud)
有关splitlines()函数的更多信息.