1、list.append(obj)         向列表中加入一个对象obj

 fruits = ['apple', 'pear', 'orange']
>>> fruits.append('apple')
>>> fruits
['apple', 'pear', 'orange', 'apple']

2、list.count(obj)             返回一个对象obj在列表中出现的次数

>>> fruits.count('apple')
2

3、list.extend(seq)          把序列seq的内容加入到列表中

>>> seq = ['banana', 'strawberry']
>>> fruits.extend(seq)
>>> fruits
['apple', 'pear', 'orange', 'apple', 'banana', 'strawberry']

4、list.index(obj, i=0, j=len(list))

返回 list[k] == obj 的 k 值,而且 k 的范围在 i<=k<j;否则引发 ValueError 异常。

>>> fruits.index('orange',0, len(list))
2
>>> fruits.index('lemon',0, len(list)) Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
fruits.index('lemon',0, len(list))
ValueError: 'lemon' is not in list

5、list.insert(index, obj)             在索引量为 index 的位置插入对象obj

>>> fruits.insert(3, 'lemon')
>>> fruits
['apple', 'pear', 'orange', 'lemon', 'apple', 'banana', 'strawberry']

6、list.pop(index=-1)                  删除并返回指定位置的对象,默认是最后一个对象

>>> fruits.pop()
'strawberry'
>>> fruits
['apple', 'pear', 'orange', 'lemon', 'apple', 'banana']

7、list.remove(obj)                     从列表中删除找到的第一个obj对象。假设不存在则返回一个ValueError错误。


>>> fruits.remove('apple')
>>> fruits
['pear', 'orange', 'lemon', 'apple', 'banana']
>>> fruits.remove('strawberry') Traceback (most recent call last):
  File "<pyshell#25>", line 1, in <module>
    fruits.remove('strawberry')
ValueError: list.remove(x): x not in list

8、list.reverse()             原地翻转列表

>>> fruits.reverse()
>>> fruits
['banana', 'apple', 'lemon', 'orange', 'pear']

9、list.sort(func=None,key=None,
reverse=False)

        以指定的方式排序列表中的成员,假设 func 和 key 參数指定,则依照指定的方式比較各个元素,假设 reverse 标志被置为True,则列表以反序排列。

>>> fruits.sort()
>>> fruits
['apple', 'banana', 'lemon', 'orange', 'pear']
>>> fruits.sort(reverse=True)
>>> fruits
['pear', 'orange', 'lemon', 'banana', 'apple']

版权声明:本文博主原创文章。博客,未经同意不得转载。

python常用类型的内置函数列表的更多相关文章

  1. 查看python 3中的内置函数列表,以及函数功能描述

    >>> dir(__builtins__)//查看内置函数(BIF)列表 ['ArithmeticError', 'AssertionError', 'AttributeError' ...

  2. python常用操作和内置函数

    一.常用数据处理方法. 1.索引:按照号码将对应位置的数据取出使用 2.list将任意类型数据用逗号分割存在列表中 3.range:产生一堆数字(顾头不顾尾) 4.切片:可以从复制数据的一部分,不影响 ...

  3. python 类(object)的内置函数

    python 类(object)的内置函数 # python 类(object)的内置函数 ### 首先 #### 以__双下划线开头的内置函数 __ #### __往往会在某些时候被自动调用,例如之 ...

  4. JMeter ----内置函数列表

    Jmeter有两种类型的函数: 用户定义的静态值(或变量) 内置函数 用户定义的静态值允许用户定义变量时被替换为静态的值测试树编译并提交运行.需要注意的是,变量目前无法嵌套,即${Var${N}}不起 ...

  5. Python标准库:内置函数hasattr(object, name)

    Python标准库:内置函数hasattr(object, name) 本函数是用来判断对象object的属性(name表示)是否存在.如果属性(name表示)存在,则返回True,否则返回False ...

  6. python字符串——"奇葩“的内置函数

      一.前言 python编程语言里的字符串与我们初期所学的c语言内的字符串还是有一定不同的,比如python字符串里的内置函数就比语言的要多得多:字符串内的书写格式也会有一点差异,例:字符串内含有引 ...

  7. 人生苦短之我用Python篇(深浅拷贝、常用模块、内置函数)

    深浅拷贝 有时候,尤其是当你在处理可变对象时,你可能想要复制一个对象,然后对其做出一些改变而不希望影响原来的对象.这就是Python的copy所发挥作用的地方. 定义了当对你的类的实例调用copy.c ...

  8. python笔记-5(内置函数)

    一.内置函数 1.abs()--取绝对值函数 print(abs(-0.11)) x=-0.01 y=0.11 print(abs(x),abs(y)) ----------------------- ...

  9. Python基础学习五 内置函数

    1.函数补充: 1)函数返回值return可以有多个 2)补充示例: nums = [0,1,2,3,4,5,6,7,8] #如何将list里面的元素变为字符串类型 new_nums = [str(x ...

随机推荐

  1. rcp(插件开发)org.eclipse.ui.decorators 使用

    org.eclipse.ui.decorators这个扩展点可以为对应的节点添加不同的图标显示. 使用方式都差不多,以下就转载一下使用方式: 1.添加扩展点 org.eclipse.ui.decora ...

  2. 计算机视觉与模式识别代码合集第二版three

    计算机视觉与模式识别代码合集第二版three     Topic Name Reference code Optical Flow Horn and Schunck's Optical Flow   ...

  3. android水平循环滚动控件

    CycleScrollView.java package com.example.test; import android.content.Context; import android.graphi ...

  4. 全国各大 oj 分类题集...

    各种题集从易到难刷到手软  你准备好了吗? 准备剁手吧

  5. Cocos2d-x串算出Size方法

    项目需要,根据所输入的字符串,的需要计算串帐户Size. 包代码如下面.只需要传递一个字符串,您可以返回Size: Size ChartDemoScene::calculateFontSize(con ...

  6. 我在开发网站后得出的asp.Net网站优化总结

    原文:我在开发网站后得出的asp.Net网站优化总结 asp.Net网站优化总结: 1.数据库优化: 首先是对查询语句的优化,开发时为了图快可以不考虑,但是后期维护时就必须要优化(比如:你调用代码生成 ...

  7. 关于windows系统影子账户的问题

    在这之前,需要大家了解几个问题,一个是SID,一个是账号的F值. Windows账户的SID 在Windows系统中,系统会为每个用户账户建立一个唯一的安全标识符(Security Identifie ...

  8. Exception in thread "http-apr-8080-exec-6" java.lang.OutOfMemoryError: PermGen space 解决!

    Exception in thread "http-apr-8080-exec-6" java.lang.OutOfMemoryError: PermGen space at ja ...

  9. hdu 4925 贪心 自己从小到大做数据找方法规律

    http://acm.hdu.edu.cn/showproblem.php?pid=4925 自己逐个做数据找规律.提供下我的找的: 1 2 1 3 2 2 2 3 3 3 然后发现这种矩阵是最优的: ...

  10. tar.bz2解压

    bzip2 -d gcc-4.1.0.tar.bz2 tar -xvf gcc-4.1.0.tar 或 tar -xvf *.tar