📜  要列出的字符串 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:27.735000             🧑  作者: Mango

代码示例2
>>> names='''
...       Apple
...       Ball
...       Cat'''
>>> names
'\n      Apple\n      Ball\n      Cat'
>>> names_list = [y for y in (x.strip() for x in names.splitlines()) if y]
>>> # if x.strip() is used to remove empty lines
>>> names_list
['Apple', 'Ball', 'Cat']