我有4个变量(1,2,3,4),我必须编写一段Python代码来将存储在这些变量中的值移动到左边,最左边的值在最右边的变量enter image description here中结束
发布于 2019-11-10 06:15:29
您可以创建新列表并在正确的位置复制值:
previous_list = [1,2,3,4]
new_list = []
for i in range(1, len(previous_list)):
new_list.append(previous_list[i])
new_list.append(previous_list[0])
print(new_list)发布于 2019-11-10 06:15:30
lis = [1,2,3,4]
lis = lis[1:] + [lis[0]]切片的一个很好的描述可以在here找到
发布于 2019-11-10 06:16:46
尝试:
x=[1,2,3,4]
y=(x+x)[1:len(x)+1]
print(y)输出:
[2, 3, 4, 1]
[Program finished]https://stackoverflow.com/questions/58783955
复制相似问题