木心

毕竟几人真得鹿,不知终日梦为鱼

导航

python基础--列表

  python列表list

# 列表
list = ['a', 'b', 'c']
for str in list:
    print(str)
    
# append()方法来添加列表项
list2 = []
list2.append("hello")
list2.append(" python")
print(list2)

# del:根据索引来删除列表的元素
del list2[1]
print(list2)

# len(列表):长度
print(len(list))

# 组合
print(list + list2)

# 重复
print(list * 2)

# 元素是否存在于列表中
if 'a' in list:
    print('list列表中包含有\'a\'')

 

  pop:删除最后一个

  remove(obj): 根据内容删除一个

  del list[索引]: 根据索引删除

 

python列表的方法:https://www.runoob.com/python/python-lists.html

 

posted on 2019-10-08 00:02  wenbin_ouyang  阅读(178)  评论(0编辑  收藏  举报