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

python基础--列表

 

相关文章:

  • 2022-01-03
  • 2022-01-17
  • 2021-10-01
  • 2021-08-08
  • 2022-02-05
  • 2021-08-30
  • 2022-12-23
猜你喜欢
  • 2021-06-05
  • 2021-06-12
  • 2021-06-18
  • 2021-07-26
  • 2022-01-01
  • 2021-12-25
相关资源
相似解决方案