擅长:python、mysql、java
<p>下面是一个简单的解决方案,它只使用<a href="https://automatetheboringstuff.com/chapter4/" rel="nofollow">Chapter 4</a>中已经包含的语法:</p>
<pre><code>def toString(arr):
s = ''
for i in range(len(arr)):
if i > 0:
if i == len(arr) - 1:
# last one
s = s + ' and '
else:
# second, third, ...
s = s + ', '
s = s + arr[i];
return s
</code></pre>
<p>它适用于具有任意数量元素的数组。在</p>