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. ASP-Server.Transfer-Response.Redirect

    Server.Transfer Transfer 方法把一个 ASP 文件中创建的所有状态信息(所有 application/session 变量以及所有 request 集合中的项目)发送(传输)到 ...

  2. Qt里的原子操作QAtomicInteger

    所谓原子操作,即一系列复杂的操作能一气呵成,中间不被其他的操作打断.这在多线程程序中尤其常见,但要实现这种功能,既要考虑程序的良好设计,又要关心特定平台的体系结构和相关编译器对原子特性的支持程度.所以 ...

  3. docker devise相关错误

    rake aborted!Devise.secret_key was not set. Please add the following to your Devise initializer: con ...

  4. rails 增删改查

    class InvoicesController < ApplicationController def index @invoices = Invoice.all end def show @ ...

  5. 47求1+2+3+...+n

    题目描述 求1+2+3+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C). 用递归 public class Soluti ...

  6. Loadrunder之脚本篇——参数化方法

    导语 参数化旨在模拟多数据来进行测试,所以再选择参数化你明确你参数化的内容! 方法一 1.确定需要参数化的内容 2.选中需要参数化的内容 3.右键选中的内容->Replace with a Pa ...

  7. Hibernate多对多关联

    多对多关联: 示例:Teacher和Student,一个Teacher可以教很多student,一个Student也可以被很多teacher教   多对多单向关联 Teacher知道自己教了哪些学生, ...

  8. 树莓派打造对话机器人 Python(转)

    工具列表 1. **树莓派**(型号不要求,本人使用的是3B) 2. **usb麦克风**(某宝有卖,我就不打广告了) 用来录音 3. **音响或者喇叭**(某宝也有卖) 用来播放 以上就是需要的工具 ...

  9. 【HackerRank】Lonely Integer

    There are N integers in an array A. All but one integer occur in pairs. Your task is to find out the ...

  10. 【HackerRank】Utopian tree

    The Utopian tree goes through 2 cycles of growth every year. The first growth cycle of the tree occu ...