您的位置:首页 > 移动开发

「Python」list.append和list.extend

2017-08-17 20:09 302 查看
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 17 19:55:39 2017

@author: Shawn Yuen
"""

list1 = ['a', 'b', 'c']
print("list1 is ", list1)
print("the type of list1 is ", type(list1))

#extend
#list2 = ['d', 'e', 'f']
list2 = ['d']
list1.extend(list2)
print("the result of extend is ", list1)
print("the length of list3 is ", len(list1))
print("the last entry of list1 is ", list1[-1])

#append
list3 = ['a', 'b', 'c']
list3.append(list2)
print("the result of append is ", list3)
print("the length of list3 is ", len(list3))
print("the last entry of list3 is ", list3[-1])

print("the last entry of list1 is equal to that of list3?", list3[-1] is list1[-1])
参考资料
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  小锋子