擅长:python、mysql、java
<p>如果您使用的是<code>python3</code>,那么可以使用<a href="https://www.python.org/dev/peps/pep-3132/" rel="nofollow">extended iterable unpacking</a>:</p>
<pre><code>In [14]: l = ["1", "2", "3", "4", "5"]
In [15]: *_, c, b, a = l
In [16]: a,b,c
Out[16]: ('5', '4', '3')
</code></pre>
<p>根据您的编辑,如果您想从列表末尾开始获取<code>n</code>项并对其执行某些功能,可以使用reversed从末尾开始,并从列表中获取<a href="https://docs.python.org/3.5/library/itertools.html#itertools.islice" rel="nofollow">islice</a>n项:</p>
<pre><code>In [51]: from itertools import islice
In [52]: l = ["1", "2", "3", "4", "5"]
In [53]: c, b, a = map("something{}".format , islice(reversed(l), 3))
In [54]: a,b,c
Out[54]: ('something3', 'something4', 'something5')
</code></pre>
<p>或者以循环为例:</p>
<pre><code>In [55]: for ele in islice(reversed(l), 3):
....: print("Something{}".format(ele))
....:
Something5
Something4
Something3
</code></pre>