1、合并

>>> l1=[1,2,3,'e']
>>> l2=['f',34,'feel']
>>> l1+l2
[1, 2, 3, 'e', 'f', 34, 'feel']

2、重复

>>> l1
[1, 2, 3, 'e']
>>> l1*2
[1, 2, 3, 'e', 1, 2, 3, 'e']

3、增加   append  extend

>>> l1=[1,2,3,'e']
>>> l1.append(4)
>>> l1
[1, 2, 3, 'e', 4]
>>> l2=['hello','world']
>>> l1.extend(l2)
>>> l1
[1, 2, 3, 'e', 4, 'hello', 'world']

插入  insert     插入位置 插入内容

>>> l2.insert(2,'a')
>>> l2
['hello', 'world', 'a']
>>> l2.insert(4,'a')
>>> l2
['hello', 'world', 'a', 'a']

4、计数  L.count

>>> l2
['hello', 'world', 'a', 'a']
>>> help(list.insert)

>>> l2.count('a')
2
>>> l2.count('l')
0

5、搜索位置 L.index

index(...)
L.index(value, [start, [stop]]) -> integer -- return first index of value.

>>> l2
['hello', 'world', 'a', 'a']
>>> l2.index('a')
2

6、排序  sort

>>> l2
['hello', 'world', 'a', 'a']
>>> l2.sort()
>>> l2
['a', 'a', 'hello', 'world']       直接改变列表

>>> l2.sort(reverse=True)    倒序排序设置reverse为True
>>> l2
['world', 'hello', 'a', 'a']

反转 reverse     切片

>>> l2
['world', 'hello', 'a', 'a']
>>> l2.reverse()
>>> l2
['a', 'a', 'hello', 'world']
>>> l2[::-1]
['world', 'hello', 'a', 'a']

7、删除元素

>>> l2
['a', 'a', 'hello', 'world']
>>> del l2[0]
>>> l2
['a', 'hello', 'world']

>>> l2.remove('hello')    按值删除

>>> l2
['a', 'world']

>>> l1=['a','hello',1,4,34,'er']
>>> l1.pop()        默认删除最后一个元素,
'er'  
>>> l1
['a', 'hello', 1, 4, 34]
>>> l1.pop(0)   按索引删除
'a'
>>> l1
['hello', 1, 4, 34]

8、使用切片修改元素

>>> l1=[1,2,3,4,5,6,7,8,9,10]

>>> l1[0:8:2]=['a']    不连续元素

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: attempt to assign sequence of size 1 to extended slice of size 4
>>> l1[0:8:2]=['a','b','c','d']
>>> l1
['a', 2, 'b', 4, 'c', 6, 'd', 8, 9, 10]
>>> l1=[1,2,3,4,5,6,7,8,9,10]
>>> l1[1:3]=['a']     连续元素
>>> l1
[1, 'a', 4, 5, 6, 7, 8, 9, 10]

9、列表推导

>>> L=[x**2 for x in range(1,10) if x%2!=0]
>>> L
[1, 9, 25, 49, 81]

10、列表生成 list

>>> a=list('hello')
>>> a
['h', 'e', 'l', 'l', 'o']

python3 列表属性的更多相关文章

  1. [CSS]列表属性(List)

      CSS 列表属性(List) 属性 描述 CSS list-style 在一个声明中设置所有的列表属性. 1 list-style-image 将图象设置为列表项标记. 1 list-style- ...

  2. python3列表

    Python3 列表 list python的矩阵 python中矩阵可以用双层列表表示 Python列表脚本操作符 len([1, 2, 3]) 3 长度 [1, 2, 3] + [4, 5, 6] ...

  3. Python直接改变实例化对象的列表属性的值 导致在flask中接口多次请求报错

    错误原理实例如下: class One(): list = [1, 2, 3] @classmethod def get_copy_list(cls): # copy一份list,这样对list的改变 ...

  4. Python3 列表 copy() 方法

    描述 Python3 列表 copy() 方法用于复制(浅拷贝)列表(父不变,子变),类似于 a[:]. 语法 copy() 方法语法: L.copy() 参数 无. 返回值 返回复制(浅拷贝)后的新 ...

  5. Python3 列表 clear() 方法

    描述 Python3 列表 clear() 方法用于清空列表,类似于 del a[:]. 语法 clear() 方法语法: L.clear() 参数 无. 返回值 该方法没有返回值. 实例 以下实例展 ...

  6. python3 字符串属性(一)

    python3 字符串属性 >>> a='hello world' >>> dir(a) ['__add__', '__class__', '__contains_ ...

  7. python009 Python3 列表

    Python3 列表序列是Python中最基本的数据结构.序列中的每个元素都分配一个数字 - 它的位置,或索引,第一个索引是0,第二个索引是1,依此类推.Python有6个序列的内置类型,但最常见的是 ...

  8. css列表属性和样式控制

    如下图是360浏览器主页的内容,上边有导航,下边是新闻列表,这种布局很常见,今天就来学习css列表属性之后并制作它. 列表属性 html有三种类型的列表:无序列表,有序列表和自定义列表.设置列表标记有 ...

  9. css中的列表属性

    list-style-type设定引导列表的符号类型,可以设置多种符号类型,值为disc.circle.square等 list-style-image使用图像作为定制列表的符号 list-style ...

随机推荐

  1. JS基础知识简介

    使用js的三种方式 1.HTML标签内嵌js <button onclick="javascript:alert(真点啊)">有本事点我</button> ...

  2. Python 是怎么火起来的?

    Python 之父 Guido 正在设计 Python 语言,结果家里突然潜入一条大蟒蛇,一番激烈斗争,大蟒蛇把 Guido 叔生吞进肚,并洋洋自得:So Who is Guido Van Rossu ...

  3. centos7 安装vue

    1: npm安装: 2: 报错:  bash: vue: command not found 执行npm install --global vue-cli 后 执行 vue 报错 bash: vue: ...

  4. DP专题(不定期更新)

    1.UVa 11584 Partitioning by Palindromes(字符串区间dp) 题意:给出一个字符串,划分为若干字串,保证每个字串都是回文串,同时划分数目最小. 思路:dp[i]表示 ...

  5. foreach使用和函数

    2016-04-25 一.foreach( 对集合每个元素的引用 in 集合 ) { } int[] a = new int[5]{1,2,3,4,5}; foreach( int b in a ) ...

  6. Python 4 函数的参数,内置函数,装饰器,生成器,迭代器,

    一.函数的参数: 1.位置参数:调用函数时根据函数定义的参数位置来传递参数. 2.关键字参数:用于函数调用,通过“键-值”形式加以指定.可以让函数更加清晰.容易使用,同时也清除了参数的顺序需求. 3. ...

  7. HttpServlet---getLastModified与缓存

    在HttpServlet中重写service方法的代码如下: protected void service(HttpServletRequest req, HttpServletResponse re ...

  8. 系统封装接口层 cmsis_os

    在这个实时操作系统泛滥的年代,有这么一个系统封装接口层还是蛮有必要的.前些时间偶然间在STM32最新的固件库中就发现了这个系统封装接口,当时就把自己所用的系统进行封装.直到最近KEIL5.0发现其中所 ...

  9. 主攻ASP.NET.4.5.1 MVC5.0之重生:在项目中使用zTree jQuery 树插件

    效果图和json格式 Controllers代码 using HR.Models; using HR.Models.Repository; /***************************** ...

  10. HashMap,LinkedHashMap和TreeMap的区别

    Map主要用于存储健值对,根据键得到值,因此不允许键重复(重复会覆盖),但允许值重复. 1. HashMap Hashmap是一个最常用的Map,它根据键的HashCode值存储数据,根据键可以直接获 ...