Python 列表常用功能详解

class list(object):    """    list() -> new empty list    list(iterable) -> new list initialized from iterable‘s items    """    def append(self, p_object): # real signature unknown; restored from __doc__        """ L.append(object) -> None -- append object to end """        pass        在列表的末尾追加一个元素        example:        new_list = [‘andy‘,‘rain‘]        new_list.append(‘hello‘)        print(new_list)

        result:        [‘andy‘, ‘rain‘, ‘hello‘]

    def clear(self): # real signature unknown; restored from __doc__        """ L.clear() -> None -- remove all items from L """        pass        清空一个列表        example:        new_list = [‘andy‘,‘rain‘]        new_list.clear()        print(new_list)

        result:        []

    def copy(self): # real signature unknown; restored from __doc__        """ L.copy() -> list -- a shallow copy of L """        return []        复制一个列表        example:        new_list = [‘andy‘,‘rain‘]        news_list = new_list.copy()        print(news_list)

        result:        [‘andy‘, ‘rain‘]

    def count(self, value): # real signature unknown; restored from __doc__        """ L.count(value) -> integer -- return number of occurrences of value """        return 0        统计列表列表中同一个元素有多少个        example:        new_list = [‘andy‘,‘rain‘,‘andy‘]        print(new_list.count(‘andy‘))

        result:        2

    def extend(self, iterable): # real signature unknown; restored from __doc__        """ L.extend(iterable) -> None -- extend list by appending elements from the iterable """        pass        在现有的列表中追加列表、元组、字符串        example:        new_list = []        new_list.extend(‘andy‘)        print(new_list)

        new_list = []        new_list.extend([‘andy‘,‘hello‘])        print(new_list)

        result:        [‘a‘, ‘n‘, ‘d‘, ‘y‘]        [‘andy‘, ‘hello‘]

    def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__        """        L.index(value, [start, [stop]]) -> integer -- return first index of value.        Raises ValueError if the value is not present.        """        return 0        获取列表中某个元素的索引位置        example:        new_list = [‘andy‘,‘rain‘]        print(new_list.index(‘andy‘))

        result:        0

    def insert(self, index, p_object): # real signature unknown; restored from __doc__        """ L.insert(index, object) -- insert object before index """        pass        在列表指定位置插入一个元素(必须要指定一个插入位置、即索引)        example:        new_list = [‘andy‘,‘rain‘]        new_list.insert(0,‘first‘)        print(new_list)

        result:        [‘first‘, ‘andy‘, ‘rain‘]

    def pop(self, index=None): # real signature unknown; restored from __doc__        """        L.pop([index]) -> item -- remove and return item at index (default last).        Raises IndexError if list is empty or index is out of range.        """        pass        删除列表元素:指定所以、删除指定元素;不指定元素默认删除最后一个元素        example:        new_list = [‘andy‘,‘rain‘,‘andy‘]        new_list.pop(0)        print(new_list)

        new_list = [‘andy‘,‘rain‘,‘andy‘]        new_list.pop()        print(new_list)

        result:        [‘rain‘, ‘andy‘]        [‘andy‘, ‘rain‘]

    def remove(self, value): # real signature unknown; restored from __doc__        """        L.remove(value) -> None -- remove first occurrence of value.        Raises ValueError if the value is not present.        """        pass        删除指定元素的左数第一个        example:        new_list = [‘andy‘,‘rain‘,‘andy‘]        new_list.remove(‘andy‘)        print(new_list)

        result:        [‘rain‘, ‘hello‘]

    def reverse(self): # real signature unknown; restored from __doc__        """ L.reverse() -- reverse *IN PLACE* """        pass        #列表反转        new_list = [1,2,3,4,5,6,7,8,9,10]        new_list.reverse()        print(new_list)

        result:        [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

    def sort(self, key=None, reverse=False): # real signature unknown; restored from __doc__        """ L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE* """        pass        #列表排序: 特殊字符优先级最高、然后是数字、然后是大些字母、然后是小写字母        new_list = [5,1,3,2,6,7,9,8,10,4]        new_list.sort()        print(new_list)

        new_list = [‘z‘,‘!‘,‘*‘,‘2‘,‘a‘,‘~‘,‘b‘,‘A‘,‘c‘,‘a‘,‘1‘,‘/‘,‘?‘,‘%‘]        new_list.sort()        print(new_list)

        result:        [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]        [‘!‘, ‘%‘, ‘*‘, ‘/‘, ‘1‘, ‘2‘, ‘?‘, ‘A‘, ‘a‘, ‘a‘, ‘b‘, ‘c‘, ‘z‘, ‘~‘]

    def __add__(self, *args, **kwargs): # real signature unknown        """ Return self+value. """        pass

    def __contains__(self, *args, **kwargs): # real signature unknown        """ Return key in self. """        pass

    def __delitem__(self, *args, **kwargs): # real signature unknown        """ Delete self[key]. """        pass

    def __eq__(self, *args, **kwargs): # real signature unknown        """ Return self==value. """        pass

    def __getattribute__(self, *args, **kwargs): # real signature unknown        """ Return getattr(self, name). """        pass

    def __getitem__(self, y): # real signature unknown; restored from __doc__        """ x.__getitem__(y) <==> x[y] """        pass

    def __ge__(self, *args, **kwargs): # real signature unknown        """ Return self>=value. """        pass

    def __gt__(self, *args, **kwargs): # real signature unknown        """ Return self>value. """        pass

    def __iadd__(self, *args, **kwargs): # real signature unknown        """ Implement self+=value. """        pass

    def __imul__(self, *args, **kwargs): # real signature unknown        """ Implement self*=value. """        pass

    def __init__(self, seq=()): # known special case of list.__init__        """        list() -> new empty list        list(iterable) -> new list initialized from iterable‘s items        # (copied from class doc)        """        pass

    def __iter__(self, *args, **kwargs): # real signature unknown        """ Implement iter(self). """        pass

    def __len__(self, *args, **kwargs): # real signature unknown        """ Return len(self). """        pass

    def __le__(self, *args, **kwargs): # real signature unknown        """ Return self<=value. """        pass

    def __lt__(self, *args, **kwargs): # real signature unknown        """ Return self<value. """        pass

    def __mul__(self, *args, **kwargs): # real signature unknown        """ Return self*value.n """        pass

    @staticmethod # known case of __new__    def __new__(*args, **kwargs): # real signature unknown        """ Create and return a new object.  See help(type) for accurate signature. """        pass

    def __ne__(self, *args, **kwargs): # real signature unknown        """ Return self!=value. """        pass

    def __repr__(self, *args, **kwargs): # real signature unknown        """ Return repr(self). """        pass

    def __reversed__(self): # real signature unknown; restored from __doc__        """ L.__reversed__() -- return a reverse iterator over the list """        pass

    def __rmul__(self, *args, **kwargs): # real signature unknown        """ Return self*value. """        pass

    def __setitem__(self, *args, **kwargs): # real signature unknown        """ Set self[key] to value. """        pass

    def __sizeof__(self): # real signature unknown; restored from __doc__        """ L.__sizeof__() -- size of L in memory, in bytes """        pass

    __hash__ = None
时间: 2024-10-05 20:15:11

Python 列表常用功能详解的相关文章

python中常用模块详解二

log模块的讲解 1 Python 使用logging模块记录日志涉及四个主要类,使用官方文档中的概括最为合适: 2 3 logger提供了应用程序可以直接使用的接口API: 4 handler将(logger创建的)日志记录发送到合适的目的输出: 5 formatter决定日志记录的最终输出格式 6 filter提供了细度设备来决定输出哪条日志记录: 7 8 logger 9 每个程序在输出信息之前都要获得一个Logger.Logger通常对应了程序的模块名, 10 比如聊天工具的图形界面模块

python 列表、元组 详解

python中有6种序列的内置类型,分别为:列表,元组,字符串,Unicode字符串,buffer对象和xrange对象 列表和元组是最常见两种类型. 下面将以列表(list)和元组(tuple)为例对序列操作进行详细的讲解: 一.列表(list) 列表序列操作有:索引.切片.修改.追加.插入.删除.扩展.统计.排序(翻转).获取下标.拷贝 1. 索引 (list[i]) 列表的索引序号(又称为下标)如下图所示,该序列一共拥有n个元素, 从左到右索引是从 0 开始,  n-1 为最后一个元素 从

fiddler抓包常用功能详解

一.基础部分: 1.设置代理ip及端口,tools --> telerik fiddler options --> connections -->勾选 " Allow romote computers to connect",端口修改成自己想要的端口号. 2.设置手机代理或浏览器代理,手机进入与fiddler相同局域网络WIFI --> 修改网络 --> 代理选择"手动" --> 输入ip.端口(浏览器设置代理不作描述). 二.f

Python list(列表)功能详解

Python List append()方法 描述 append() 方法用于在列表末尾添加新的对象. 语法 append()方法语法: list.append(obj) 参数 obj -- 添加到列表末尾的对象. 返回值 该方法无返回值,但是会修改原来的列表. 实例 以下实例展示了 append()函数的使用方法: #!/usr/bin/python aList = [123, 'xyz', 'zara', 'abc']; aList.append( 2009 ); print "Update

Fiddler抓取https请求 &amp; Fiddler抓包工具常用功能详解

大家好,我是TT,互联网测试行业多年,没有牛逼的背景,也没有什么可炫耀的,唯独比他人更努力,在职场打拼.遇到过的坑,走过的弯路,愿意与大家分享,分享自己的经验,少走弯路.首发于个人公众号[测试架构师] 原文如下: 先来看一个小故事: 小T在测试APP时,打开某个页面展示异常,于是就跑到客户端开发小A那里说:"你这个页面做的有问题,页面展示异常":小A说:"这哪是我的问题,你去找后台吧,后台接口返回数据有问题":小T就屁颠屁颠的跑到后台接口开发小M那里说:"

Jmeter常用功能详解

[Test plan(测试计划)界面]                                                      [线程组界面] 右键点击 测试计划--->添加--->Threads(users)--->线程组,就可以成功添加一个线程组了. Jmeter中最重要的就是线程组了,线程组就相当于用户活动,一个线程组就相当于有一个用户活动,添加多个线程组就相当于模拟多个用户活动对服务器进行测试. [循环控制器界面] 右键点击线程组--->添加---->

Python 列表浅复制详解

在文章<Python 数据类型>里边介绍了列表的用法,其中列表有个 copy() 方法,意思是复制一个相同的列表.例如 1 names = ["小明", "小红", "小黑", "小黄", "小白"] 2 # 把 names 复制,赋值给 names2 变量 3 names2 = names.copy() 4 # 分别输出 names names2 5 print(names) 6 print(

list(列表)功能详解

class list(object):    """    list() -> new empty list    list(iterable) -> new list initialized from iterable's items    """    def append(self, p_object): # real signature unknown; restored from __doc__        "&

css3圆角和渐变2种常用功能详解

Css3圆角讲解:想必大家对于图片,背景圆角,都不陌生吧, 圆角语法:border-radius:圆角值: 这个值可以使用:em ,ex,pt,px,百分比; Border-radius跟margin,padding差不多 Border-radius:lefttop,righttop,rightbottom,leftbottom. <div class="box1"></div> .box1{width:200px;height:100px;border-rad