根据python中的范围用新行分割字符串

时间:2019-12-05 06:40:30

标签: python python-3.x

str = '''Hello world! Whats up?'''
rangeSplitLiast = [range(5, 11), range(18, 21)]

我需要以下输出:

世界你好!

怎么了?

1 个答案:

答案 0 :(得分: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?