根据python中的范围,用新行将字符串分割开[关闭]

问题描述 投票:-4回答:1
str = '''Hello world! Whats up?'''
rangeSplitLiast = [range(5, 11), range(18, 21)]

我需要下面的输出:

Hello world!

怎么了?

python python-3.x
1个回答
2
投票

您可以尝试类似:

str1 = '''Hello world! Whats up?'''
rangeSplitLiast = [str1[0:12], str1[13:21]]
for string in rangeSplitLiast:
    print(string, end="\n\n")

输出:

Hello world!

whats up?
© www.soinside.com 2019 - 2024. All rights reserved.