python列表的基础操作
Operation | Result | Trans |
---|---|---|
x in s |
True if an item of s is equal to x, else False |
x值是否在s列表中 |
x not in s |
False if an item of s is equal to x, else True |
x值是否不在s列表中 |
s + t |
the concatenation of s and t | 拼接s和t |
s * n or n * s |
equivalent to adding s to itself n times | 将s列表重复n遍 |
s[i] |
ith item of s, origin 0 | 取s列表中某一个值 |
s[i:j] |
slice of s from i to j | 切片方式取s列表中 i 到(j-1)的连续索引对应的值 |
s[i:j:k] |
slice of s from i to j with step k | 切片方式取s列表中 i 到(j-1),步长为k的索引对应的值 |
len(s) |
length of s | 获取s列表的长度 等同于 s.__len__() |
min(s) |
smallest item of s | 获取s列表中的最小值 |
max(s) |
largest item of s | 获取s列表中的最大值 |
s.index(x[, i[, j]]) |
index of the first occurrence of x in s (at or after index i and before index j) | 获取x值在s列表中(从索引 i 到(j-1))的索引(第一个出现的) |
s.count(x) |
total number of occurrences of x in s | 获取x值在s列表中的个数 |
Operation | Result | Trans |
---|---|---|
s[i] = x |
item i of s is replaced by x | |
s[i:j] = t |
slice of s from i to j is replaced by the contents of the iterable t | |
del s[i:j] |
same as s[i:j] = [] |
|
s[i:j:k] = t |
the elements of s[i:j:k] are replaced by those of t |
|
del s[i:j:k] |
removes the elements of s[i:j:k] from the list |
|
s.append(x) |
appends x to the end of the sequence (same as s[len(s):len(s)] = [x] ) |
|
s.clear() |
removes all items from s (same as dels[:] ) |
|
s.copy() |
creates a shallow copy of s (same as s[:] ) |
|
s.extend(t) or s += t |
extends s with the contents of t (for the most part the same as s[len(s):len(s)]= t ) |
|
s *= n |
updates s with its contents repeated n times | |
s.insert(i, x) |
inserts x into s at the index given by i(same as s[i:i] = [x] ) |
|
s.pop([i]) |
retrieves the item at i and also removes it from s | |
s.remove(x) |
remove the first item from s where s[i]== x |
|
s.reverse() |
reverses the items of s in place |
python列表的基础操作的更多相关文章
- 【Learning Python】【第二章】Python基础类型和基础操作
基础类型: 整型: py 3.0解决了整数溢出的问题,意味着整型不必考虑32位,64位,有无符号等问题,你写一个1亿亿亿,就是1亿亿亿,不会溢出 a = 10 ** 240 print(a) 执行以上 ...
- Python列表的切片操作
在Python列表中分片是一个很重要的操作,有以下几个注意的点: 切片时不包含最后一位,如下例子中,要取最后一位,从0开始算应该是到7就可以取,但是需要8才能取 2. 默认取值步长为1,即每 ...
- python列表的常用操作
列表是python的基础数据类型之一 ,其他编程语言也有类似的数据类型.比如JS中的数 组, java中的数组等等. 它是以[ ]括起来, 每个元素用' , '隔开而且可以存放各种数据类型: 列表是p ...
- python文件的基础操作
import os print(,'-')) print(os.getcwd()) print(,'-')) print(os.listdir()) print(,'-')) print(os.lis ...
- python 列表(list)常用操作
a = [1,2,3,4,1,1,1,1] 删除操作 删除元素1 a.remove(1) 删除第二个元素 del a[1] 默认删除最后一个,给脚标就会删除指定脚标元素 pop() 方法 a.pop( ...
- python列表的切片操作允许索引超出范围
其余的不说,列表切片操作允许索引超出范围:
- python列表和元组操作
列表 列表(list)是python以及其他语言中最常用到的数据结构之一.Python使用中括号[ ]来解析列表.列表是可变的(mutable)—可以改变列表的内容. 定义列表 names = ['m ...
- Python列表及元组操作
#列表(一组有序数据的组合就是列表) #创建列表 #空列表 var = list()#var = [] print(var,type(var)) #具有多个元素的列表 var = ['风','水',' ...
- 【Python数组及其基础操作】【numpy ndarray】
一.创建数组 在python中创建数组最简单的办法就是使用array函数.它接受一切序列型的对象,然后产生一个含有传入数据的numpy数组.其中,嵌套序列(比如由一组等长列表组成的列表)会被转换为一个 ...
随机推荐
- flock
为了确保操作的有效性和完整性,可以通过锁机制将并发状态转换成串行状态.作为锁机制中的一种,PHP的文件锁也是为了应对资源竞争.假设一个应用场景,在存在较大并发的情况下,通过fwrite向文件尾部多次有 ...
- datetime模块
# 其中days = -2,可以根据需要进行替换,这样就可以得到不同需要的日期了. # # 另外:可以通过strftime方法,指定时间的输出格式. # # 除了以上输入的 %Y-%m-%d ...
- 斐讯 天天牛绑定教程 邀请码:8vozbf
天天牛邀请码 8vozbf 可以领取4代牛 最近斐讯推出了天天牛养成计划. 不过官方没有任何的指示教程,所以个人分享一个教程给大家. 1. 先把把旧的钱包备份一下 ,切记!! 而且一定要记得自己设的密 ...
- re正则表达式匹配字符串中的数字
re.match(r'.*-(\d*).html',url_1).group(1) \d+匹配1次或者多次数字,注意这里不要写成*,因为即便是小数,小数点之前也得有一个数字:\.?这个是匹配小数点的, ...
- python爬虫,使用BeautifulSoup解析爬出来的HTML代码时报错
UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for thi ...
- Pycharm 常用快捷键与设置
pycharm高频率使用的快捷键 Ctrl+Shift+F10 运行当前的页面 Ctrl + / 注释(取消注释)选择的行 Ctrl+Shift+F 高级查找 Shift + Enter 开始新行 T ...
- s21day20 python笔记
s21day20 python笔记 一.内容回顾 面向对象的三大特性 封装 函数封装到类 数据封装到对象 继承 多态 二.成员 2.1 类成员 类变量(静态字段) 定义:写在类的下一级,和方法同一级 ...
- 记录一次axios请求造成的数组初始化失败
axios请求是一个异步的请求,简单来讲就是在做其他事情的时候可以把这个先放一边等其他的事情做完后再来做这件事件. 我之前这样调用了一个方法: mounted() { this.first() thi ...
- VMware 虚拟机安装-->wrf、cmaq安装
微信关注公众号 “软件安装管家” 下载并安装VMware 下面简要记载我的安装和设置步骤: 下载解压,右键以管理员方式运行 安装好了之后 双击桌面 的VMware 输入许可证密钥:AA510-2DF1 ...
- python 启动时报错无法正常启动(0xc000007b)请单击“确定”关闭应用程序的解决办法
这是一个自己非常傻逼的问题,但是还是想记录下来 晚上安装python,不管是命令提示符中运行还是python直接打开,都提示报错 各种百度,各种查找排除以后,皆不能解决错误 最后发现:特么64位系统下 ...