a = [1,2,3,4,5] b = a[1:] b.append(a[0]) print(b)
时间: 2023-12-29 15:05:16 浏览: 76
图片切换(1,2,3,4,5)
The output of this code is:
[2, 3, 4, 5, 1]
Explanation:
- We start by defining a list `a` with the values `[1,2,3,4,5]`.
- We then create a new list `b` by slicing `a` from index 1 to the end (`a[1:]`). This means that `b` contains all the elements of `a` starting from the second one (`2,3,4,5`).
- We then use the `append()` method to add the first element of `a` (`1`) to the end of `b`.
- Finally, we print the resulting list `b`, which is `[2, 3, 4, 5, 1]`.
阅读全文