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数组.其中,嵌套序列(比如由一组等长列表组成的列表)会被转换为一个 ...
随机推荐
- Javascript学习---倒计时
function fn() { var now = new Date(); // 此时此刻的时间 var old = new Date(2018, 9, 30); // 2018,6,25 var t ...
- 洛谷P1966 【火柴排队】
题解 P1966 [火柴排队] 说明: 在数学中有个公式: (a1-b1)^2+(a2-b2)^2<(a2-b1)^2+(a1-b2)^2 (你可以自己试着证一下) 两列火柴对应的两根火柴在各列 ...
- L2-014 列车调度 (25 分)
L2-014 列车调度 (25 分) 火车站的列车调度铁轨的结构如下图所示. 两端分别是一条入口(Entrance)轨道和一条出口(Exit)轨道,它们之间有N条平行的轨道.每趟列车从入口可以选择 ...
- iis7 绑定多个ssl证书
默认情况下iis上只能绑定一个ssl证书,如果多的话 会只认一个. 停止IIS 运行[ CMD] , 输入 [iisreset /STOP] 第一步:修改配置文件. 然后打开:C:/Windows ...
- CentOS无法使用ifconfig和root密码修改
初学Linux,总是有许多问题,这次就遇到了这个问题: 想使用ifconfig命令查看一下虚拟机的ip地址,结果发现ifconfig命令无法使用,总是显示找不到ifconfig这个命令. 上网查询帮助 ...
- 数字特征值-java
题目内容: 对数字求特征值是常用的编码算法,奇偶特征是一种简单的特征值.对于一个整数,从个位开始对每一位数字编号,个位是1号,十位是2号,以此类推.这个整数在第n位上的数字记作x,如果x和n的奇偶性相 ...
- easyui获取正在编辑行的代码
easyui获取正在编辑行的代码……没这个真不知道怎么搞0.0可能这问题还要弄半天……卧槽 ...等于是笔记下来 : var ed = $("dg").datagrid('get ...
- HDU 2176:取(m堆)石子游戏(Nim博弈)
取(m堆)石子游戏 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- python爬虫之常见的加密方式
前言 数据加密与解密通常是为了保证数据在传输过程中的安全性,自古以来就一直存在,古代主要应用在战争领域,战争中会有很多情报信息要传递,这些重要的信息都会经过加密,在发送到对应的人手上. 现代 ,在网络 ...
- 记一次网络原因导致的mysql连接中断问题(druid)
date: 2018-04-19 21:00 tag: java,mysql,exception,mat,调试,jvm 工具: gceasy.io, MAT 线上系统出现一个诡异的bug,通过heap ...