python中实现列表元素的交换
1、
>>> a = ["aa","bb","cc","dd","ee"]
>>> temp = a[1] ## 引入变量
>>> temp
'bb'
>>> a[1] = a[3]
>>> a
['aa', 'dd', 'cc', 'dd', 'ee']
>>> a[3] = temp
>>> a
['aa', 'dd', 'cc', 'bb', 'ee']
2、
>>> a = ["aa","bb","cc","dd","ee"]
>>> a
['aa', 'bb', 'cc', 'dd', 'ee']
>>> a[1],a[3] = a[3],a[1] ## 直接交换
>>> a
['aa', 'dd', 'cc', 'bb', 'ee']