• 列表


    li=[1,2,"age",["11","1"],"abc"]

    中括号括起来

    分割每一个元素

    列表中的元素可以是数字 字符串 列表 布尔值 都能放进去

    li=[1,2,"age",["11","1"],"abc"]
    print(li[2])
    print(li[3:4])
    
    
    age
    [['11', '1']]

    索引取值

    print( li [] )

    切片,切片结果也是列表

    
    修改
    li=[1,2,"age",["11","1"],"abc"]
    li[3]= "name"
    print(li)
    
    li=[1,2,"age",["11","1"],"abc"]
    li[0:3]=["aaa","bbb","ccc"]
    print(li)
    删除
    li=[1,2,"age",["11","1"],"abc"]
    del li[2]
    print(li)
    切片删除
    li=[1,2,"age",["11","1"],"abc"]
    del li[0:2]
    print(li)
    in 操作
    li=[1,2,"age",["11","1"],"abc"]
    v="age" in li
    print(v)
    # 字符串转换成列表
    s="qwertyuiop"
    new_li=list(s)
    print(new_li)
    
    
    
    ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p']
    
    # 只能转换可迭代的 数字不可以
    # 列表转换成字符串
    s=""
    li=[1,2,"age","11","1","abc"]
    for i in li:
        s=s+str(i)
    print(s)
    
    
    
    12age111abc
    
    
    # 列表内没有数字时可以用join 将列表转换成字符串
    li=["age","11","1","abc"]
    v="".join(li)
    print(v)
    
    
    age111abc
  • 相关阅读:
    robot framework 初始化清除
    python获取命令行参数
    行业基金
    Ubuntu关闭开机自启项
    ubuntu18.04安装adb
    JavaScript
    centos关闭开机自启项
    CSDN值得学习的专栏
    ubuntu和centos操作命令对比
    linux解压文件命令
  • 原文地址:https://www.cnblogs.com/panyizuoshan/p/10595144.html
Copyright © 2020-2023  润新知