
上QQ阅读APP看书,第一时间看更新
Negative syntax
One more thing you can do is have this negative syntax:
x[-2:]
The output is as follows:
[5, 6]
By saying x[-2:], this means that I want the last two elements in the list. This means that go backwards two from the end, and that will give me 5 and 6, because those are the last two things on my list.