Python实战之列表list的详细简单练习2
name_list = ['zhangsan','lisi','wangermazi','xiaotaoqi'] print(name_list) # name_list.append("william") # ['zhangsan', 'lisi', 'wangermazi', 'xiaotaoqi', 'william'] # count = name_list.count('lisi') # print("count=",count) # count=1 # name_list2 = ['william','alex'] # name_list.extend(name_list2) # ['zhangsan', 'lisi', 'wangermazi', 'xiaotaoqi', 'william', 'alex'] # name_index = name_list.index("xiaotaoqi") # print("name_index=",name_index) # # name_index= 3 # # name_index = name_list.index("xiaotaoqi1") # print("name_index=",name_index) # print(name_list) # # Traceback (most recent call last): # File "C:/Users/Python-learn/list_test.py", line 14, in <module> # name_index = name_list.index("xiaotaoqi1") # ValueError: 'xiaotaoqi1' is not in list # name_list.insert(2,"William") # ['zhangsan', 'lisi', 'William', 'wangermazi', 'xiaotaoqi'] # name_list.pop() # ['zhangsan', 'lisi', 'wangermazi'] # name_list.pop(2) # ['zhangsan', 'lisi', 'xiaotaoqi'] # name_list.remove("lisi") # ['zhangsan', 'wangermazi', 'xiaotaoqi'] # name_list.reverse() # ['xiaotaoqi', 'wangermazi', 'lisi', 'zhangsan'] num_list = [1,3,6,1,2,9,4,5,3] # print(name_list.__add__(num_list)) # ['zhangsan', 'lisi', 'wangermazi', 'xiaotaoqi', 1, 3, 6, 1, 2, 9, 4, 5, 3] print(name_list.__contains__("lisi")) # True # print(name_list.__delitem__(2)) # ['zhangsan', 'lisi', 'xiaotaoqi'] print(name_list.__de) print(name_list)
posted on 2017-06-30 17:13 William126 阅读(128) 评论(0) 编辑 收藏 举报