Python开发(基础):列表List

  • List 内置函数
#!/usr/bin/env python
# -*- coding:utf-8 -*-

# 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__
#         在list尾部追加
#         """ L.append(object) -- append object to end """
#         pass
li = [‘alex‘,‘tom‘,‘aric‘,‘tony‘,‘alex‘]
li.append(‘jason‘)
print li
#[‘alex‘, ‘tom‘, ‘aric‘, ‘tony‘, ‘alex‘, ‘jason‘]
#     def count(self, value):  # real signature unknown; restored from __doc__
#         返回list中某个值出现的次数
#         """ L.count(value) -> integer -- return number of occurrences of value """
#         return 0
print li.count(‘alex‘)
#     def extend(self, iterable):  # real signature unknown; restored from __doc__
#         将一个可迭代的对象追加到list尾部
#         """ L.extend(iterable) -- extend list by appending elements from the iterable """
#         pass
li.extend((‘steven‘,‘whales‘))
print li
#[‘alex‘, ‘tom‘, ‘aric‘, ‘tony‘, ‘alex‘, ‘jason‘, ‘steven‘, ‘whales‘]
li.extend(‘Tomcat‘)
#[‘alex‘, ‘tom‘, ‘aric‘, ‘tony‘, ‘alex‘, ‘jason‘, ‘steven‘, ‘whales‘, ‘T‘, ‘o‘, ‘m‘, ‘c‘, ‘a‘, ‘t‘]
print li
#     def index(self, value, start=None, stop=None):  # real signature unknown; restored from __doc__
#         返回list中某个值第一次出现的索引位置
#         """
#         L.index(value, [start, [stop]]) -> integer -- return first index of value.
#         Raises ValueError if the value is not present.
#         """
#         return 0
print li.index(‘alex‘)
#0
#   def insert(self, index, p_object):  # real signature unknown; restored from __doc__
#         在list的某个索引位置插入一个值
#         """ L.insert(index, object) -- insert object before index """
#         pass
li.insert(2,‘Andy‘)
print li
#[‘alex‘, ‘tom‘, ‘Andy‘, ‘aric‘, ‘tony‘, ‘alex‘, ‘jason‘, ‘steven‘, ‘whales‘, ‘T‘, ‘o‘, ‘m‘, ‘c‘, ‘a‘, ‘t‘]
#     def pop(self, index=None):  # real signature unknown; restored from __doc__
#         """
#         取出list中最后一个索引位置上的值,并删除
#         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
last_value = li.pop()
print last_value;
print li
#t
#[‘alex‘, ‘tom‘, ‘Andy‘, ‘aric‘, ‘tony‘, ‘alex‘, ‘jason‘, ‘steven‘, ‘whales‘, ‘T‘, ‘o‘, ‘m‘, ‘c‘, ‘a‘]
#     def remove(self, value):  # real signature unknown; restored from __doc__
#         """
#         删除list中某个值,从左往右,只删除一次,如果存在多个相同的值需要全部删除,需执行多次
#         L.remove(value) -- remove first occurrence of value.
#         Raises ValueError if the value is not present.
#         """
#         pass
li.remove(‘alex‘)
print li
#[‘tom‘, ‘Andy‘, ‘aric‘, ‘tony‘, ‘alex‘, ‘jason‘, ‘steven‘, ‘whales‘, ‘T‘, ‘o‘, ‘m‘, ‘c‘, ‘a‘]
#     def reverse(self):  # real signature unknown; restored from __doc__
#         反转
#         """ L.reverse() -- reverse *IN PLACE* """
#         pass
li.reverse()
print li
#[‘a‘, ‘c‘, ‘m‘, ‘o‘, ‘T‘, ‘whales‘, ‘steven‘, ‘jason‘, ‘alex‘, ‘tony‘, ‘aric‘, ‘Andy‘, ‘tom‘]
#     def sort(self, cmp=None, key=None, reverse=False):  # real signature unknown; restored from __doc__
#         """
#         排序
#         L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*;
#         cmp(x, y) -> -1, 0, 1
#         """
#         pass
li.sort()
print li
#[‘Andy‘, ‘T‘, ‘a‘, ‘alex‘, ‘aric‘, ‘c‘, ‘jason‘, ‘m‘, ‘o‘, ‘steven‘, ‘tom‘, ‘tony‘, ‘whales‘]
#     def __add__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__add__(y) <==> x+y """
#         pass
#
#     def __contains__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__contains__(y) <==> y in x """
#         pass
#
#     def __delitem__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__delitem__(y) <==> del x[y] """
#         pass
#
#     def __delslice__(self, i, j):  # real signature unknown; restored from __doc__
#         """
#         x.__delslice__(i, j) <==> del x[i:j]
#
#                    Use of negative indices is not supported.
#         """
#         pass
#
#     def __eq__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__eq__(y) <==> x==y """
#         pass
#
#     def __getattribute__(self, name):  # real signature unknown; restored from __doc__
#         """ x.__getattribute__(‘name‘) <==> x.name """
#         pass
#
#     def __getitem__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__getitem__(y) <==> x[y] """
#         pass
#
#     def __getslice__(self, i, j):  # real signature unknown; restored from __doc__
#         """
#         x.__getslice__(i, j) <==> x[i:j]
#
#                    Use of negative indices is not supported.
#         """
#         pass
#
#     def __ge__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__ge__(y) <==> x>=y """
#         pass
#
#     def __gt__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__gt__(y) <==> x>y """
#         pass
#
#     def __iadd__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__iadd__(y) <==> x+=y """
#         pass
#
#     def __imul__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__imul__(y) <==> x*=y """
#         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):  # real signature unknown; restored from __doc__
#         """ x.__iter__() <==> iter(x) """
#         pass
#
#     def __len__(self):  # real signature unknown; restored from __doc__
#         """ x.__len__() <==> len(x) """
#         pass
#
#     def __le__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__le__(y) <==> x<=y """
#         pass
#
#     def __lt__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__lt__(y) <==> x<y """
#         pass
#
#     def __mul__(self, n):  # real signature unknown; restored from __doc__
#         """ x.__mul__(n) <==> x*n """
#         pass
#
#     @staticmethod  # known case of __new__
#     def __new__(S, *more):  # real signature unknown; restored from __doc__
#         """ T.__new__(S, ...) -> a new object with type S, a subtype of T """
#         pass
#
#     def __ne__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__ne__(y) <==> x!=y """
#         pass
#
#     def __repr__(self):  # real signature unknown; restored from __doc__
#         """ x.__repr__() <==> repr(x) """
#         pass
#
#     def __reversed__(self):  # real signature unknown; restored from __doc__
#         """ L.__reversed__() -- return a reverse iterator over the list """
#         pass
#
#     def __rmul__(self, n):  # real signature unknown; restored from __doc__
#         """ x.__rmul__(n) <==> n*x """
#         pass
#
#     def __setitem__(self, i, y):  # real signature unknown; restored from __doc__
#         """ x.__setitem__(i, y) <==> x[i]=y """
#         pass
#
#     def __setslice__(self, i, j, y):  # real signature unknown; restored from __doc__
#         """
#         x.__setslice__(i, j, y) <==> x[i:j]=y
#
#                    Use  of negative indices is not supported.
#         """
#         pass
#
#     def __sizeof__(self):  # real signature unknown; restored from __doc__
#         """ L.__sizeof__() -- size of L in memory, in bytes """
#         pass
#
#     __hash__ = None
时间: 2024-07-30 08:38:00

Python开发(基础):列表List的相关文章

python开发基础:列表操作

一,列表操作 1 #!/usr/bin/env python 2 #_*_coding:utf-8_*_ 3 4 # l=[1,2,3] #l=list([1,2,3]) 5 # print(type(l)) 6 7 #pat1===>优先掌握部分 8 # 索引 9 # 10 # 切片 11 # l=['a','b','c','d','e','f'] 12 13 # print(l[1:5]) 14 # print(l[1:5:2]) 15 # print(l[2:5]) 16 # print(

Python开发基础-Day9-生成器、三元表达式、列表生成式、生成器表达式

生成器 生成器函数:函数体内包含有yield关键字,该函数执行的结果是生成器,生成器在本质上就是迭代器. def foo(): print('first------>') yield 1 print('second----->') yield 2 print('third----->') yield 3 print('fouth----->') g=foo() from collections import Iterator print(isinstance(g,Iterator)

Python开发基础--- Event对象、队列和多进程基础

Event对象 用于线程间通信,即程序中的其一个线程需要通过判断某个线程的状态来确定自己下一步的操作,就用到了event对象 event对象默认为假(Flase),即遇到event对象在等待就阻塞线程的执行. 示例1:主线程和子线程间通信,代码模拟连接服务器 1 import threading 2 import time 3 event=threading.Event() 4 5 def foo(): 6 print('wait server...') 7 event.wait() #括号里可

Python开发基础-Day31 Event对象、队列和多进程基础

Event对象 用于线程间通信,即程序中的其一个线程需要通过判断某个线程的状态来确定自己下一步的操作,就用到了event对象 event对象默认为假(Flase),即遇到event对象在等待就阻塞线程的执行. 示例1:主线程和子线程间通信,代码模拟连接服务器 1 import threading 2 import time 3 event=threading.Event() 4 5 def foo(): 6 print('wait server...') 7 event.wait() #括号里可

python开发基础篇(一)

变量及其定义规范 1 #变量名(相当于门牌号,指向值所在的空间),等号,变量值 2 name='Egon' 3 sex='male' 4 age=18 5 level=10 变量的定义规范 #1. 变量名只能是 字母.数字或下划线的任意组合 #2. 变量名的第一个字符不能是数字 #3. 关键字不能声明为变量名['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', '

Python开发基础-Day23try异常处理、socket套接字基础1

异常处理 错误 程序里的错误一般分为两种: 1.语法错误,这种错误,根本过不了python解释器的语法检测,必须在程序执行前就改正 2.逻辑错误,人为造成的错误,如数据类型错误.调用方法错误等,这些解释器是不会进行检测的,只有在执行的过程中才能抛出的错误 异常 异常是python解释器在运行程序的过程中遇到错误所抛出的信息,如: Python异常种类: 常用异常: 1 AttributeError 试图访问一个对象没有的树形,比如foo.x,但是foo没有属性x 2 IOError 输入/输出异

Python开发基础--- 进程间通信、进程池、协程

进程间通信 进程彼此之间互相隔离,要实现进程间通信(IPC),multiprocessing模块支持两种形式:队列和管道,这两种方式都是使用消息传递的. 进程队列queue 不同于线程queue,进程queue的生成是用multiprocessing模块生成的. 在生成子进程的时候,会将代码拷贝到子进程中执行一遍,及子进程拥有和主进程内容一样的不同的名称空间. 示例1: 1 import multiprocessing 2 def foo(): 3 q.put([11,'hello',True]

Python开发基础-Day14正则表达式和re模块

正则表达式 就其本质而言,正则表达式(或 re)是一种小型的.高度专业化的编程语言,(在Python中)它内嵌在Python中,并通过 re 模块实现.正则表达式模式被编译成一系列的字节码,然后由用 C 编写的匹配引擎执行. 字符匹配(普通字符,元字符): 1 普通字符(完全匹配):大多数字符和字母都会和自身匹配 1 >>> import re 2 >>> res='hello world good morning' 3 >>> re.findall(

Python开发基础----异常处理、socket套接字基础1

异常处理 错误 程序里的错误一般分为两种: 1.语法错误,这种错误,根本过不了python解释器的语法检测,必须在程序执行前就改正 2.逻辑错误,人为造成的错误,如数据类型错误.调用方法错误等,这些解释器是不会进行检测的,只有在执行的过程中才能抛出的错误 异常 异常是python解释器在运行程序的过程中遇到错误所抛出的信息,如: Python异常种类: 常用异常: 1 AttributeError 试图访问一个对象没有的树形,比如foo.x,但是foo没有属性x 2 IOError 输入/输出异

python开发基础篇(二)

python数据类型 1 什么是数据? x=10,10是我们要存储的数据 2 为何数据要分不同的类型 数据是用来表示状态的,不同的状态就应该用不同的类型的数据去表示 3 数据类型 数字(整形,长整形,浮点型,复数) 字符串 字节串:在介绍字符编码时介绍字节bytes类型 列表 元组 字典 集合 4 按照以下几个点展开数据类型的学习 #一:基本使用 用途 定义方式 常用操作+内置的方法 #二:该类型总结 存一个值or存多个值 只能存一个值 可以存多个值,值都可以是什么类型 有序or无序 可变or不