擅长:python、mysql、java
<p>使用<a href="https://stackoverflow.com/a/930398/2157793">Slice Notation</a>:</p>
<pre><code>def addFirstAndLast(x):
return x[0] + x[-1]
</code></pre>
<p><strong>x[0]</strong>=将为您提供列表的索引0<sup>th</sup>,即第一个值。</p>
<p><strong>x[-1]</strong>=将给您列表的最后一个元素。</p>