擅长:python、mysql、java
<p>python中的<code>list</code>对象是一个<strong>可变对象</strong>,这意味着它通过引用而不是通过值传递到函数中。因此,您已经在适当地更改了<code>seq</code>,并且没有必要修改<code>return</code>语句</p>
<pre><code>def swapPositions(list, pos1, pos2):
list[pos1], list[pos2] = list[pos2], list[pos1]
seq=['abd','dfs','sdfs','fds','fsd','fsd']
swapPositions(seq,2,3)
print(seq)
# returns ['abd', 'dfs', 'fds', 'sdfs', 'fsd', 'fsd']
</code></pre>