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列表的基础操作的更多相关文章

  1. 【Learning Python】【第二章】Python基础类型和基础操作

    基础类型: 整型: py 3.0解决了整数溢出的问题,意味着整型不必考虑32位,64位,有无符号等问题,你写一个1亿亿亿,就是1亿亿亿,不会溢出 a = 10 ** 240 print(a) 执行以上 ...

  2. Python列表的切片操作

    在Python列表中分片是一个很重要的操作,有以下几个注意的点: 切片时不包含最后一位,如下例子中,要取最后一位,从0开始算应该是到7就可以取,但是需要8才能取 2.      默认取值步长为1,即每 ...

  3. python列表的常用操作

    列表是python的基础数据类型之一 ,其他编程语言也有类似的数据类型.比如JS中的数 组, java中的数组等等. 它是以[ ]括起来, 每个元素用' , '隔开而且可以存放各种数据类型: 列表是p ...

  4. python文件的基础操作

    import os print(,'-')) print(os.getcwd()) print(,'-')) print(os.listdir()) print(,'-')) print(os.lis ...

  5. python 列表(list)常用操作

    a = [1,2,3,4,1,1,1,1] 删除操作 删除元素1 a.remove(1) 删除第二个元素 del a[1] 默认删除最后一个,给脚标就会删除指定脚标元素 pop() 方法 a.pop( ...

  6. python列表的切片操作允许索引超出范围

    其余的不说,列表切片操作允许索引超出范围:

  7. python列表和元组操作

    列表 列表(list)是python以及其他语言中最常用到的数据结构之一.Python使用中括号[ ]来解析列表.列表是可变的(mutable)—可以改变列表的内容. 定义列表 names = ['m ...

  8. Python列表及元组操作

    #列表(一组有序数据的组合就是列表) #创建列表 #空列表 var = list()#var = [] print(var,type(var)) #具有多个元素的列表 var = ['风','水',' ...

  9. 【Python数组及其基础操作】【numpy ndarray】

    一.创建数组 在python中创建数组最简单的办法就是使用array函数.它接受一切序列型的对象,然后产生一个含有传入数据的numpy数组.其中,嵌套序列(比如由一组等长列表组成的列表)会被转换为一个 ...

随机推荐

  1. c语言 实验1

    实验结论 Part 1 首次运行Part 1的几个实验内容时会产生错误,原因如下 有时忘记在主函数中的每行末尾加分号 return 0 时空格错误导致程序运行失败 # include <stdi ...

  2. OFBiz项目简介

    记得最早使用OFBiz是十年前在公司的一个EA游戏项目中,用来实现玩家在游戏中购买各种游戏装备.当由于自己刚出校门不久,经验也少,对软件产品架构.思想.目的了解不透彻,不明白OFBiz设计上的优点,本 ...

  3. linux 安装 ftp 实现文件共享

    转载:http://blog.sina.com.cn/s/blog_165e646820102xe1q.html 参考:1.http://www.cnblogs.com/mrcln/p/6179673 ...

  4. DG Switch over

    DG切换迁移Switch over切换文档 本篇文档,整体结构:1.切换前检查确认2.DG切换角色操作3.切换后检查确认 目录:一.切换前检查确认1.数据库版本2.DG架构,IP信息及切换角色前后3. ...

  5. Dapper使用技巧分享

    Dapper是轻量级的.net ORM框架,配合linq和泛型,让C#操作数据的代码简洁.高效又灵活!最近的工作项目中使用了Dapper,在这里分享一些实用技巧.阅读之前需要了解一些基本的使用方法,参 ...

  6. 正确处理下载文件时HTTP头的编码问题(Content-Disposition)

    留坑 参考: 正确处理下载文件时HTTP头的编码问题(Content-Disposition) HTTP协议header中Content-Disposition中文文件名乱码 文件下载,content ...

  7. 关于rabbitmq的介绍

    原文转载:http://blog.csdn.net/whycold/article/details/41119807 保护原帖,尊重技术,致敬工匠! 一.简介 MQ全称为Message Queue, ...

  8. CF867E: Buy Low Sell High(贪心, STL) (hdu6438)

    Description 有nn个城市,第ii个城市商品价格为aiai​,从11城市出发依次经过这nn个城市到达n n城市,在每个城市可以把手头商品出售也可以至多买一个商品,问最大收益. Input 第 ...

  9. Java基于opencv实现图像数字识别(二)—基本流程

    Java基于opencv实现图像数字识别(二)-基本流程 做一个项目之前呢,我们应该有一个总体把握,或者是进度条:来一步步的督促着我们来完成这个项目,在我们正式开始前呢,我们先讨论下流程. 我做的主要 ...

  10. linux虚拟机时间同步

    方法来源于网上,但是经过验证是可行的. 作为linux学习的新手,开始学习时总会遇到各种各样的麻烦,每次开机发现自己的虚拟机总是与当前的时间相差几个小时到几天不等,查阅网上经验,我的做法是 1.使用y ...