zoukankan      html  css  js  c++  java
  • 列表list(序列)、元组tuple(序列)

    len(seq)、max(seq)、min(seq)、enumerate(seq,num=0)、zip(seq1,seq2)、sum(seq)

    list()、tuple()、str()浅拷贝

    sorted(seq)、reversed(seq)不改变元数据,返回序列

    In [66]: lst
    Out[66]: ['qwe', 147, '4']
    
    In [67]: lst.append([1,2,3])
    
    In [68]: lst
    Out[68]: ['qwe', 147, '4', [1, 2, 3]]
    
    In [69]: lst.extend([4,5,6])
    
    In [70]: lst
    Out[70]: ['qwe', 147, '4', [1, 2, 3], 4, 5, 6]
    
    In [71]: lst.count(4)
    Out[71]: 1
    
    In [72]: lst.index(4)
    Out[72]: 4
    
    In [74]: lst.insert(2,'lll')
    
    In [75]: lst
    Out[75]: ['qwe', 147, 'lll', '4', [1, 2, 3], 4, 5, 6]
    
    In [76]: lst.pop()
    Out[76]: 6
    
    In [77]: lst.pop(1)
    Out[77]: 147
    
    In [78]: lst.reverse()
    
    In [79]: lst
    Out[79]: [5, 4, [1, 2, 3], '4', 'lll', 'qwe']
    
    In [82]: lst = [7,4,0]
    
    In [83]: lst.sort()  # 默认归并排序
    
    In [84]: lst
    Out[84]: [0, 4, 7]

    堆栈 stack:后进先出,用列表中的append和pop可模拟出堆栈结构

    In [91]: a = []
    
    In [92]: a.append(1)
    
    In [93]: a.append(2)
    
    In [94]: a.append(3)
    
    In [95]: a
    Out[95]: [1, 2, 3]
    
    In [96]: a.pop()
    Out[96]: 3

    队列queue:先进先出,用列表中的append和pop[0]可模拟出队列结构

    其它还有列表解析

    元组:

    创建单元素元组:(1,)

    适用操作:()、count()、index()、len()、list()、max()、min()、repr()、str()、tuple()、type()、[]、[ : ]、*、%、+、(not)in

    将列表解析中括号换成小括号则变成生成器

    渐变 --> 突变
  • 相关阅读:
    7.3形成团队结构
    第7章 设计构架
    第6章 空中交通管制:高可用性设计案例分析
    5.5安全性战术
    第5章实现质量属性
    4..4.7 使用一般场景进行沟通的概念
    4.4.3性能
    第II部分创建构架
    3.3.2使用结构
    docker容器互联
  • 原文地址:https://www.cnblogs.com/lybpy/p/8151307.html
Copyright © 2011-2022 走看看