Python3 列表list合并的4种方法
方法1: 直接使用"+"号合并列表
- aList = [1,2,3]
- bList = ['www', 'pythontab.com']
- cList = aList + bList
- dList = bList + aList
- print(cList)
- print(dList)
- # 结果:
- [1, 2, 3, 'www', 'pythontab.com']
- ['www', 'pythontab.com', 1, 2, 3]
方法2: 使用extend方法
- aList = [1,2,3]
- bList = ['www', 'pythontab.com']
- aList.extend(bList)
- print(aList)
- # 结果:
- [1, 2, 3, 'www', 'pythontab.com']
方法3: 使用切片
- aList = [1,2,3]
- bList = ['www', 'pythontab.com']
- aList[len(aList):len(aList)] = bList # len