您现在的位置是:首页 > 文章详情

learning_python_list

日期:2019-07-23点击:422

数据结构

  • python 中的数据结构

    • 不可变类型

      • int:整型
      • float:浮点型
      • bool:布尔型
      • str:字符串
    • 可变类型

      • list:列表
      • tuple:元组
      • set:集合
      • dict:字典
  • 获取数据类型:type()

如:

In [1]: type(1) Out[1]: int In [2]: type(1.1) Out[2]: float In [3]: type(True) Out[3]: bool In [3]: type(False) Out[3]: bool 

列表

  • 列表(list)([])是一种存储大量数据的存储模型,可以对数据进行增、删、改、查操作。
  • 增加数据

    • append(self, object): Append object to the end of the list.
    • insert(self, index, object): Insert object before index.
    • extend(self, iterable): Extend list by appending elements from the iterable.

    • 翻译:
    • append(self, object): 在列表的末尾添加元素。
    • insert(self, index, object): 在指定位置之前插入元素。
    • extend(self, iterable): 从可迭代数据存储器中扩充到列表末尾。
  • 删除数据

    • remove(self, object): Remove first occurrence of value.Raises ValueError if the value is not present.
    • pop(self, index): Remove and return item at index (default last).Raises IndexError if list is empty or index is out of range.
    • clear(self): Remove all items from list.

    • 翻译:
    • remove(self, object): 移除列表中第一个指定数据,若指定数据不存在,抛出ValueError。
    • pop(self, index): 移除并返回列表中指定位置的数据(默认为最后一个),若列表为空或者指定位置超过范围,抛出IndexError。
    • clear(self): 移除列表中所有元素。
  • 修改数据和查询数据:根据索引
  • 其他函数

    • count(self, object): Return number of occurrences of value.
    • index(self, object, start, stop): Return first index of value.Raises ValueError if the value is not present.
    • copy(self): Return a shallow copy of the list.
    • reverse(self): Reverse IN PLACE.
    • sort(self, key, reverse): Stable sort IN PLACE.

    • 翻译
    • count(self, object): 返回指定数据在列表中的个数。
    • index(self, object, start, stop): 返回指定数据在列表中第一个位置,若指定数据不存在,抛出ValueError。
    • copy(self): 返回一个列表的拷贝。
    • reverse(self): 在列表上反转。
    • sort(self, key, reverse): 在列表上执行稳定排序。



感谢阅读,本文首发于 learning_python_list
原文链接:https://yq.aliyun.com/articles/710650
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章