列表 是一种用于保存一系列有序项目的集合。列表是使用对象与类的实例。
以下是一个列表操作的实例:
python数据结构学习之列表
如我们可以定义如下的一个shoplist类。
shoplist = [‘apple’, ‘mango’, ‘carrot’, ‘banana’]
可以使用len(shoplist)求列表长度,也即列表中元素个数。
使用shoplist.append(‘rice’)将rice添加到shoplist列表中。
使用shoplist[0]表示列表首元素。
del 列表名[i]表示删除列表中第i+1个元素。

相关文章:

  • 2022-12-23
  • 2021-10-30
  • 2021-06-24
  • 2022-12-23
  • 2021-06-28
  • 2022-01-29
  • 2021-09-11
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2018-10-31
  • 2022-12-23
  • 2021-05-25
相关资源
相似解决方案