与Python相关

问题描述 投票:0回答:1

如何从跨多行的字符串中取出某些部分?

0

我从网站获取一个字符串,它返回了

“像这样

我想要

分解它

分成部分”

(我在使用 print() 时得到了这个)

我想找到一个类似于以下内容的解决方案:

part_one = "Like this"
part_two = "and I want to"
part_three = "break it down"
part_four = "into parts"
python python-3.x string list printf
1个回答
0
投票

使用

str.splitlines()
将单个字符串分成不同的行。

splitlines()
返回一个列表。

假设您的字符串存储在

long_string
中。

strings_list = [ii for ii in long_string.splitlines() if ii != ""]
© www.soinside.com 2019 - 2024. All rights reserved.