• 列表及列表操作方法


    一、列表

      作用:多个装备,多个爱好,多门课程,多个女朋友等

      定义:[]内可以有多个任意类型的值,逗号分隔

    以下是列表的常用操作:

    l=[1,2,3] #l=list([1,2,3])
    # print(type(l))

    #pat1===》优先掌握部分
    #  索引:l=[1,2,3,4,5]
          print(l[0]) 7 #  切片
    l=['a','b','c','d','e','f']

    # print(l[1:5])
    # print(l[1:5:2])
    # print(l[2:5])
    # print(l[-1])


    #了解
    # print(l[-1:-4])
    # print(l[-4:])
    # l=['a','b','c','d','e','f']
    # print(l[-2:])

    #   追加
    # hobbies=['play','eat','sleep','study']
    # hobbies.append('girls')
    # print(hobbies)

    #   删除
    hobbies=['play','eat','sleep','study']
    # x=hobbies.pop(1) #不是单纯的删除,是删除并且把删除的元素返回,我们可以用一个变量名去接收该返回值
    # print(x)
    # print(hobbies)

    # x=hobbies.pop(0)
    # print(x)
    #
    # x=hobbies.pop(0)
    # print(x)

    #队列:先进先出
    queue_l=[]
    #入队
    # queue_l.append('first')
    # queue_l.append('second')
    # queue_l.append('third')
    # print(queue_l)
    #出队
    # print(queue_l.pop(0))
    # print(queue_l.pop(0))
    # print(queue_l.pop(0))


    #堆栈:先进后出,后进先出
    # l=[]
    # #入栈
    # l.append('first')
    # l.append('second')
    # l.append('third')
    # #出栈
    # print(l)
    # print(l.pop())
    # print(l.pop())
    # print(l.pop())

    #了解
    # del hobbies[1] #单纯的删除
    # hobbies.remove('eat') #单纯的删除,并且是指定元素去删除


    #   长度
    # hobbies=['play','eat','sleep','study']
    # print(len(hobbies))

    #   包含in
    # hobbies=['play','eat','sleep','study']
    # print('sleep' in hobbies)

    # msg='hello world egon'
    # print('egon' in msg)


    ##pat2===》掌握部分
    hobbies=['play','eat','sleep','study','eat','eat']
    # hobbies.insert(1,'walk')
    # hobbies.insert(1,['walk1','walk2','walk3'])
    # print(hobbies)

    # print(hobbies.count('eat'))
    # print(hobbies)
    # hobbies.extend(['walk1','walk2','walk3'])
    # print(hobbies)

    hobbies=['play','eat','sleep','study','eat','eat']
    # print(hobbies.index('eat'))


    #pat3===》了解部分
    hobbies=['play','eat','sleep','study','eat','eat']
    # hobbies.clear()
    # print(hobbies)

    # l=hobbies.copy()
    # print(l)

    # l=[1,2,3,4,5]
    # l.reverse()
    # print(l)

    l=[100,9,-2,11,32]
    l.sort(reverse=True)
    print(l)

  • 相关阅读:
    Powerdesigner中如何生成测试数据
    iBatis #和$的区别 把int作为参数时,转换为字符型
    config或者xml中的embedded使用方法。
    C#中发送邮件
    ASP.NET中JSON的序列化和反序列化
    AspNetPager.dll 实现分页
    oracle创建表空间
    如何进行数据库,比如ORACLE,SQL SERVER的逆向工程,将数据库导入到PD中
    DataTable转换成JSON字符串的函数
    iBatis把一个表的sqlmap配置的多个xml中。
  • 原文地址:https://www.cnblogs.com/kxllong/p/7215412.html
Copyright © 2020-2023  润新知