python:list对象的全部详细行为(每一个都有详细讲解)保证一看就会

python:list类型中所有的方法,每一种方法附带一个实例:以及解释说明

文章目录

    • python:list类型中所有的方法,每一种方法附带一个实例:以及解释说明
      • list类型中所有的方法(行为)
        • 获取方式
          • 实例
          • 详细解释(每一个都带有详细讲解)
            • append
            • clear
            • copy
            • count
            • extend
            • index
            • insert
            • pop
            • remove
            • reverse
            • sort

list类型中所有的方法(行为)

获取方式

通过help函数获取

实例
help(list)# 输出内容
Help on class list in module builtins:class list(object)|  list(iterable=(), /)|  |  Built-in mutable sequence.|  |  If no argument is given, the constructor creates a new empty list.|  The argument must be an iterable if specified.|  |  Methods defined here:|  |  __add__(self, value, /)|      Return self+value.|  |  __contains__(self, key, /)|      Return key in self.|  |  __delitem__(self, key, /)|      Delete self[key].|  |  __eq__(self, value, /)|      Return self==value.|  |  __ge__(self, value, /)|      Return self>=value.|  |  __getattribute__(self, name, /)|      Return getattr(self, name).|  |  __getitem__(...)|      x.__getitem__(y) <==> x[y]|  |  __gt__(self, value, /)|      Return self>value.|  |  __iadd__(self, value, /)|      Implement self+=value.|  |  __imul__(self, value, /)|      Implement self*=value.|  |  __init__(self, /, *args, **kwargs)|      Initialize self.  See help(type(self)) for accurate signature.|  |  __iter__(self, /)|      Implement iter(self).|  |  __le__(self, value, /)|      Return self<=value.|  |  __len__(self, /)|      Return len(self).|  |  __lt__(self, value, /)|      Return self<value.|  |  __mul__(self, value, /)|      Return self*value.|  |  __ne__(self, value, /)|      Return self!=value.|  |  __repr__(self, /)|      Return repr(self).|  |  __reversed__(self, /)|      Return a reverse iterator over the list.|  |  __rmul__(self, value, /)|      Return value*self.|  |  __setitem__(self, key, value, /)|      Set self[key] to value.|  |  __sizeof__(self, /)|      Return the size of the list in memory, in bytes.|  |  append(self, object, /)|      Append object to the end of the list.|  |  clear(self, /)|      Remove all items from list.|  |  copy(self, /)|      Return a shallow copy of the list.|  |  count(self, value, /)|      Return number of occurrences of value.|  |  extend(self, iterable, /)|      Extend list by appending elements from the iterable.|  |  index(self, value, start=0, stop=9223372036854775807, /)|      Return first index of value.|      |      Raises ValueError if the value is not present.|  |  insert(self, index, object, /)|      Insert object before index.|  |  pop(self, index=-1, /)|      Remove and return item at index (default last).|      |      Raises IndexError if list is empty or index is out of range.|  |  remove(self, value, /)|      Remove first occurrence of value.|      |      Raises ValueError if the value is not present.|  |  reverse(self, /)|      Reverse *IN PLACE*.|  |  sort(self, /, *, key=None, reverse=False)|      Sort the list in ascending order and return None.|      |      The sort is in-place (i.e. the list itself is modified) and stable (i.e. the|      order of two equal elements is maintained).|      |      If a key function is given, apply it once to each list item and sort them,|      ascending or descending, according to their function values.|      |      The reverse flag can be set to sort in descending order.|  |  ----------------------------------------------------------------------|  Class methods defined here:|  |  __class_getitem__(...) from builtins.type|      See PEP 585|  |  ----------------------------------------------------------------------|  Static methods defined here:|  |  __new__(*args, **kwargs) from builtins.type|      Create and return a new object.  See help(type) for accurate signature.|  |  ----------------------------------------------------------------------|  Data and other attributes defined here:|  |  __hash__ = None

这里有所有关于list的行为或者方法,我们这里选取这些行为

 |  append(self, object, /)|      Append object to the end of the list.|  |  clear(self, /)|      Remove all items from list.|  |  copy(self, /)|      Return a shallow copy of the list.|  |  count(self, value, /)|      Return number of occurrences of value.|  |  extend(self, iterable, /)|      Extend list by appending elements from the iterable.|  |  index(self, value, start=0, stop=9223372036854775807, /)|      Return first index of value.|      |      Raises ValueError if the value is not present.|  |  insert(self, index, object, /)|      Insert object before index.|  |  pop(self, index=-1, /)|      Remove and return item at index (default last).|      |      Raises IndexError if list is empty or index is out of range.|  |  remove(self, value, /)|      Remove first occurrence of value.|      |      Raises ValueError if the value is not present.|  |  reverse(self, /)|      Reverse *IN PLACE*.|  |  sort(self, /, *, key=None, reverse=False)|      Sort the list in ascending order and return None.|      |      The sort is in-place (i.e. the list itself is modified) and stable (i.e. the|      order of two equal elements is maintained).|      |      If a key function is given, apply it once to each list item and sort them,|      ascending or descending, according to their function values.|      |      The reverse flag can be set to sort in descending order.
详细解释(每一个都带有详细讲解)
append

解释内容

  • append(self, object, /)
    Append object to the end of the list.

参数

  • self:默认参数,表示是当前从类中实例化出来的对象
  • object:添加的对象
  • /:限制参数,表示在/之前的参数都是仅位置参数

作用

  • Append object to the end of the list.
  • 添加对象到list的末尾
clear

解释内容

  • clear(self, /)
    Remove all items from list.

参数

  • self:默认参数,表示是当前从类中实例化出来的对象
  • /:限制参数,表示在/之前的参数都是仅位置参数

作用

  • Remove all items from list.
  • 清除list中的全部元素
copy

解释内容

  • copy(self, /)
    Return a shallow copy of the list.

参数

  • self:默认参数,表示是当前从类中实例化出来的对象
  • /:限制参数,表示在/之前的参数都是仅位置参数

作用

  • Return a shallow copy of the list.
  • 返回list的浅拷贝副本

注意:

这里浅拷贝的意思为 直接把在原list上面进行拷贝 遇到list嵌套list的时候,这种可变数据类型时会出现同时变动的情况。

count

解释内容

  • count(self, value, /)
    Return number of occurrences of value.

参数

  • self:默认参数,表示是当前从类中实例化出来的对象
  • value:统计的值
  • /:限制参数,表示在/之前的参数都是仅位置参数

作用

  • Return number of occurrences of value.
  • 返回值出现的次数
extend

解释内容

  • extend(self, iterable, /)
    Extend list by appending elements from the iterable.

参数

  • self:默认参数,表示是当前从类中实例化出来的对象
  • iterable(可迭代的):可迭代的对象
  • /:限制参数,表示在/之前的参数都是仅位置参数

作用

  • Extend list by appending elements from the iterable.
  • 通过可迭代对象中的元素来扩展list
index

解释内容

  • index(self, value, start=0, stop=9223372036854775807, /)
    Return first index of value.
  • Raises ValueError if the value is not present.

参数

  • self:默认参数,表示是当前从类中实例化出来的对象
  • value:需要查找的值
  • start=0:默认参数,指从0开始
  • stop=9223372036854775807:默认参数,指至9223372036854775807结束
  • /:限制参数,表示在/之前的参数都是仅位置参数

作用

  • 返回指定值第一次出现的索引值

注意:如果值不存在,则返回ValueError的错误

insert

解释内容

  • insert(self, index, object, /)
    nsert object before index.

参数

  • self:默认参数,表示是当前从类中实例化出来的对象
  • index:插入的位置索引
  • object:插入的元素
  • /:限制参数,表示在/之前的参数都是仅位置参数

作用

  • 在索引之前插入对象
pop

解释内容

  • pop(self, index=-1, /)
    Remove and return item at index (default last).
    Raises IndexError if list is empty or index is out of range.

参数

  • self:默认参数,表示是当前从类中实例化出来的对象
  • index=-1:默认参数,默认操作最后一个元素
  • /:限制参数,表示在/之前的参数都是仅位置参数

作用

  • 移除并返回指定索引的元素,如为指定索引则默认为最后一个元素

注意:如果为空列表或者索引超过范围,则会报IndexError错误

remove

解释内容

  • remove(self, value, /)
    Remove first occurrence of value.
    Raises ValueError if the value is not present.

参数

  • self:默认参数,表示是当前从类中实例化出来的对象
  • value:要移除的值
  • /:限制参数,表示在/之前的参数都是仅位置参数

作用

  • 移除第一次出现的值

注意:如果值不存在,则会报ValueError错误

reverse

解释内容

  • reverse(self, /)
    Reverse IN PLACE.

参数

  • self:默认参数,表示是当前从类中实例化出来的对象
  • /:限制参数,表示在/之前的参数都是仅位置参数

作用

  • IN PLACE(在原地)
  • 在原地反转 – 倒序
sort

解释内容

  • sort(self, /, *, key=None, reverse=False)
    Sort the list in ascending order and return None.

参数

  • self:默认参数,表示是当前从类中实例化出来的对象
  • /:限制参数,表示在/之前的参数都是仅位置参数
  • *:限制参数,表示在 * 之后的参数都是关键字参数
  • key=None:默认返回None
  • reverse=False:默认不反转顺序

作用

  • 用来给容器排序

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/158533.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

excel表格忘记密码,如何找回?

找回和去除Excel表格密码的方法非常简单。具体步骤如下&#xff1a;第一步百度搜索【 密码帝官网 】&#xff0c;第二步点击“立即开始”在用户中心上传文件即可。这个方法既安全又简单&#xff0c;不需要下载任何软件&#xff0c;而且可以在手机和电脑上都使用。密码帝官网支持…

解除word文档限制,快速操作,步骤简单,不可错过。

想找回忘记的word文档密码或去除word文档密码吗&#xff1f;别担心&#xff01;为您提供最简便的解决方案。具体步骤如下&#xff1a;第一步&#xff0c;打开电脑或手机&#xff0c;并打开您的百度搜索引擎。第二步&#xff0c;在搜索栏中输入“密码帝官网”。第三步&#xff0…

kettle spoon连接MySQL8.0数据库报错解决方法

kettle 连接 mysql 8.0报错&#xff0c;显示无法连接到数据库服务 错误连接数据库 [11] : org.pentaho.di.core.exception.KettleDatabaseException: Error occurred while trying to connect to the databaseError connecting to database: (using class org.gjt.mm.mysql.D…

斯坦福NLP课程来了

生成式AI&#xff0c;尤其是以ChatGPT为首的大语言模型正在改变人们的生活方式&#xff0c;我想一定有小伙伴想加入NLP这个行列。 微软重磅发布4个适合初学者的机器学习资料 我在前一篇文章中分享了微软人工智能初学者课程&#xff0c;其中的【生成式AI】非常适合初学者&…

利用 Gem5 模拟器创建一个简单的配置脚本——翻译自官网

文章目录 创建简单的配置脚本gem5 配置脚本关于模拟对象的插话 创建配置文件全系统与系统调用模拟 运行Gem5 创建简单的配置脚本 本章教程将指导你如何为 gem5 设置一个简单的模拟脚本&#xff0c;并首次运行 gem5。我们假定你已完成本教程第一章的学习&#xff0c;并已成功创…

重生奇迹mu格斗怎么加点

1.力量加点 力量是格斗家的主要属性之一&#xff0c;它可以增加你的攻击力和物理伤害。因此&#xff0c;对于格斗家来说&#xff0c;力量加点是非常重要的。建议在前期将大部分的加点放在力量上&#xff0c;这样可以让你更快地杀死怪物&#xff0c;提高升级速度。 2.敏捷加点…

Java 环境其他下载2

1 Eclipse Temurin Latest Releases | Adoptium Eclipse Temurin 是由基于 OpenJDK 的开源 Java SE 产生的构建版本。Temurin 适用于 广泛的平台 以及诸多 Java SE 版本。以下列出了推荐用于生产的最新版本&#xff0c;并且定期由 Adoptium 社区发布更新和支持。迁移帮助、容器…

记华为荣耀手机调试H5

第一步&#xff1a;检测远程调试是否支持&#xff1a;微信搜索http://debugxweb.qq.com/?inspectortrue&#xff0c;显示微信首页即可 第二步&#xff1a;USB调试&#xff1a;数据线连接电脑和手机&#xff0c;手机在设置/关于手机/连续点七下Harmony Os版本&#xff0c;打开…

不是说人工智能是风口吗,那为什么工作还那么难找?

最近确实有很多媒体、机构渲染人工智能可以拿高薪&#xff0c;这在行业内也是事实&#xff0c;但前提是你有足够的竞争力&#xff0c;真的懂人工智能。 首先&#xff0c;人工智能岗位技能要求高&#xff0c;人工智能是一个涵盖了多个学科领域的综合性学科&#xff0c;包括数学、…

虹科分享 | 平衡速度与优先级:为多样化的实时需求打造嵌入式网络(3)——CAN与CANopen的实时能力与局限性

在回顾了选择具有实时能力的嵌入式通信系统的基本要求之后&#xff0c;我们现在将更详细地探讨CAN和CANopen的实时能力和局限性。 控制器局域网(CAN)协议是各个行业众多应用的基础&#xff0c;每个应用都有其独特的实时需求。CANopen和J1939等著名示例强调了该协议的多种适应性…

「浙江科聪新品发布」新品发布潜伏顶升式移动机器人专用控制器

聚焦专用车型 最小专用控制器 控制器只占整机5%&#xff0c;纵向出线方式&#xff0c;占比更小 更易插拔 整体解决方案 更具价格优势 提供整体解决方案&#xff0c;配套各类型产品设备及车体厂家 打造持久稳定使用 坚持工业级品质 采用车规级接口&#xff0c;不用其它类不可…

蓄势・前行 | 博格华纳的新能源+战略布局

10月11日-13日&#xff0c;AWC 2023深圳国际新能源及智能网汽车全产业博览会在深圳国际会展中心盛大开幕&#xff0c;此次展会现场共计接待专业观众3W余名&#xff0c;同期举办20场次主题论坛峰会&#xff0c;不仅汇聚众多中外汽车产业巨擘&#xff0c;更是一场涵盖智能驾驶、新…

PPT密码解密,简单教程,保护幻灯片内容

在创建、编辑和共享幻灯片时&#xff0c;有时会解除密码来保护幻灯片的安全。如果因为忘记密码而无法编辑或打开幻灯片&#xff0c;下面是一种安全、简单、实惠的办法来解决这个问题。 具体步骤如下&#xff1a;第一步百度搜索【密码帝官网】&#xff0c;第二步点击“立即开始”…

(内部资料)收下这几个人工智能学习秘籍!

秘籍一&#xff1a;练好基本功 学习基础知识&#xff1a;人工智能涉及多个学科领域&#xff0c;包括数学、计算机科学、统计学等。因此&#xff0c;学习基础知识是非常重要的。您可以通过学习线性代数、概率论和微积分等数学基础知识&#xff0c;以及掌握Python编程语言和常用…

变频器基础问答集1-20

1&#xff0e;电机的防护等级是什么意思&#xff1f;举例来说&#xff0c;ip23的电机指电机能够防止大于12mm的固体物体侵入&#xff0c;防止人的手指接触到内部的零件防止中等尺寸&#xff08;直径大12mm&#xff09;的外物侵入。能够防止喷洒的水侵入 &#xff0c;或防止与垂…

String类常用方法总结

目录 一.简单认识String 二.String对象的比较 1.equals 内部实现原理&#xff1a; 2.compareTo 3.compareToIgnoreCase 三.字符串查找 示例&#xff1a; 四.字符串与其他类型转化 1.数值和字符串相互转换 2.大小写相互转化 3.字符串转数组 4.格式化转化 五.字符串…

邦芒支招:利用自荐电话求职的七大技巧

​​如何利用自荐电话向招聘官推荐自己&#xff0c;现在人们在求职过程中都会自己争取面试机会&#xff0c;其中自荐电话是比较常见的一种方式&#xff0c;但是想要向面试官成功推荐自己也是不容易的&#xff0c;下面分享如何利用自荐电话向招聘官推荐自己。 ​ ​1、以对方为…

Hive VS Spark

spark是一个计算引擎&#xff0c;hive是一个存储框架。他们之间的关系就像发动机组与加油站之间的关系。 类似于spark的计算引擎还有很多&#xff0c;像mapreduce&#xff0c;flink等等。 类似于hive的存储框架也是数不胜数&#xff0c;比如pig。 最底层的存储往往都是使用h…

振南技术干货集:制冷设备大型IoT监测项目研发纪实(1)

注解目录 1.制冷设备的监测迫在眉睫 1.1 冷食的利润贡献 1.2 冷设监测系统的困难 &#xff08;制冷设备对于便利店为何如何重要&#xff1f;了解一下你所不知道的便利店和新零售行业。关于电力线载波通信的论战。&#xff09; 2、电路设计 2.1 防护电路 2.1.1 强电防护 …