【问题标题】:how to make a list that contains elements as each line of the input in python [closed]如何制作一个包含元素的列表作为python中输入的每一行[关闭]
【发布时间】:2021-03-30 08:45:42
【问题描述】:
s = "how many gallons
     of rain did you drink
                                cuckoo"

输入 3 行以上, 我想创建一个列表=["how many gallons", "of rain did you drink", "cuckoo"]

【问题讨论】:

标签: python list


【解决方案1】:

使用splitlines:

print([i.strip() for i in s.splitlines()])

输出:

['how many gallons', 'of rain did you drink', 'cuckoo']

【讨论】:

    猜你喜欢
    • 2017-11-17
    • 1970-01-01
    • 1970-01-01
    • 2021-02-02
    • 2016-07-16
    • 2020-10-20
    • 2022-06-25
    • 2018-12-03
    • 1970-01-01
    相关资源
    最近更新 更多