zoukankan      html  css  js  c++  java
  • 列表常用语法

    name=["张艺兴","吴亦凡","黄景瑜","朴海镇","朴灿烈"]
    print(name[4])
    print(name[0:2])
    print(name[-1])
    print(name[-3:-1])
    print(name[-3:])

    >>>

    朴灿烈
    ['张艺兴', '吴亦凡']
    朴灿烈
    ['黄景瑜', '朴海镇']
    ['黄景瑜', '朴海镇', '朴灿烈']

    for i in name:
    print(i)
    print(name[0:-1:2])

    >>>

    张艺兴
    ['李钟硕', '宋钟基']
    111
    黄景瑜
    朴海镇
    朴灿烈
    ['张艺兴', '111', '朴海镇']

    name.append("张云龙")
    print(name)

    >>>

    ['张艺兴', '吴亦凡', '黄景瑜', '朴海镇', '朴灿烈', '张云龙']

    name.insert(1,"李易峰")
    print(name)

    >>>

    ['张艺兴', '李易峰', '吴亦凡', '黄景瑜', '朴海镇', '朴灿烈', '张云龙']

    name[1]="宋钟基"
    print(name)

    >>>

    ['张艺兴', '宋钟基', '吴亦凡', '黄景瑜', '朴海镇', '朴灿烈', '张云龙']

    name.remove("张云龙")
    print(name)

    >>>

    ['张艺兴', '宋钟基', '吴亦凡', '黄景瑜', '朴海镇', '朴灿烈']

    del name[4]
    print(name)

    >>>

    ['张艺兴', '宋钟基', '吴亦凡', '黄景瑜', '朴灿烈']

    name.pop(2)
    print(name)

    >>>

    ['张艺兴', '宋钟基', '黄景瑜', '朴灿烈']
    
    print(name.index("宋钟基"))
    >>>
    1
     

    name=['张艺兴', '宋钟基', '吴亦凡', '黄景瑜', '朴海镇', '朴灿烈', '张云龙']
    if "朴灿烈" in name:
    print('I like he')

    >>>

    I like he

    name=['张艺兴', '宋钟基', '吴亦凡', '黄景瑜', '朴海镇', '朴灿烈', '张云龙']
    he="朴灿烈" in name
    print(he)

    >>>

    True


    列表的复制

    import copy
    name=["张艺兴",["李钟硕","宋钟基"],"吴亦凡","黄景瑜","朴海镇","朴灿烈"]

    name1=name
    name2=copy.copy(name)
    name3=name[:]
    name4=list(name)
    names=name.copy()

    name[1][1]="宋钟基好帅啊"
    name[0]="张艺兴努力努力"
    print(name)
    print(name1)
    print(name2)
    print(name3)
    print(name4)
    print(names)

    >>>

    ['张艺兴努力努力', ['李钟硕', '宋钟基好帅啊'], '吴亦凡', '黄景瑜', '朴海镇', '朴灿烈']
    ['张艺兴努力努力', ['李钟硕', '宋钟基好帅啊'], '吴亦凡', '黄景瑜', '朴海镇', '朴灿烈']
    ['张艺兴', ['李钟硕', '宋钟基好帅啊'], '吴亦凡', '黄景瑜', '朴海镇', '朴灿烈']
    ['张艺兴', ['李钟硕', '宋钟基好帅啊'], '吴亦凡', '黄景瑜', '朴海镇', '朴灿烈']
    ['张艺兴', ['李钟硕', '宋钟基好帅啊'], '吴亦凡', '黄景瑜', '朴海镇', '朴灿烈']
    ['张艺兴', ['李钟硕', '宋钟基好帅啊'], '吴亦凡', '黄景瑜', '朴海镇', '朴灿烈']
    
     
     
     
     
     
     
     




  • 相关阅读:
    Java反射在Android中的使用
    配置adb环境变量
    Android Studio 生成Release版,报Warning的解决办法
    Android Studio导入System Library步骤
    Windows 10 Java环境变量配置
    做一个有内涵的程序猿
    简述Python2与Python3的区别
    对不起,您输入的内容不合法
    python的数据类型
    python三器——装饰器/迭代器/生成器
  • 原文地址:https://www.cnblogs.com/muziyi/p/8780813.html
Copyright © 2011-2022 走看看