我的列表范围是1到20。
我输入两个数字i
和j
,并在一行上用空格隔开,以对列表进行切片。
需要在换行符上打印切片的数字。我做了以下事情:
list_1 = list(range(1,20))
i,j = [int(i) for i in input().split()]
print(list[i:j]);
例如
输入10 13
输出11, 12, 13
我希望它为newline_output。我尝试使用sep='\n'
,但失败了。我想念什么?
答案 0 :(得分:0)
尝试一下:
list_1 = list(range(1,20))
i,j = [int(i) for i in input().split()]
print(*list_1[i:j], sep="\n")
答案 1 :(得分:-1)
print("\n".join([str(item) for item in list]));
这应该为您提供所需的输出。