Skip to main content
 首页 » 编程设计

python之将文本转换为其行列表

2025年05月04日13think

我的函数输出都是在不同行上断开的所有值,我想把它变成一个列表。

The Score 
Leon the Professional 
Iron Man 

我想把它变成这样的列表:

movies= ['The Score', 'Leon the Professional', 'Iron Man'] 

我该怎么做呢?

请您参考如下方法:

假设您的输入是一个字符串。

>>> text = '''The Score 
Leon the Professional 
Iron Man''' 
>>> text.splitlines() 
['The Score', 'Leon the Professional', 'Iron Man'] 

有关 splitlines() 的更多信息功能。