python列表之extend和append方法
2020-01-29 本文已影响0人
yousa_
extend和append方法都用来扩列,区别:
#!/usr/bin/python
aList = [123, 'xyz', 'zara', 'abc', 123];
bList = [2009, 'manni'];
aList.extend(bList)
print ("Extended List : ", aList)
Extended List : [123, 'xyz', 'zara', 'abc', 123, 2009, 'manni']
#!/usr/bin/python
aList = [123, 'xyz', 'zara', 'abc', 123];
bList = [2009, 'manni'];
aList.append(bList)
print ("Extended List : ", aList)
Extended List : [123, 'xyz', 'zara', 'abc', 123, [2009, 'manni']]