zoukankan      html  css  js  c++  java
  • python 入门到实践第三章

    name = ["alex","crya","toto","hanlun"]
    message = "i ilke you , we are fimey "
    print(name)
    print(name[1])
    print(name[2])
    print(name[-1])
    '''展示裂变内的值'''
    print(name[0].title() + message )
    print(name[1].title() + message )
    print(name[2].title() + message )
    print(name[3].title() + message )
    '''新增修改删除列表'''
    name[0] = "crystal"#需改列表中第一个元素的内容
    print(name)
    name.append("timi")#列表末尾新增一个元素
    print(name)
    number = [] # 定义一个空的列表
    number.append("0")#新增number列表中的第一个元素
    number.append("1")
    number.append("2")
    number.append("3")
    number.append("4")
    print(number)
    number.append(5)#在列表末尾新增一个元素
    print(number)
    print(number[-1],number[-2])#打印列表末尾和倒数第二位的元素
    motorcycles = ["honda","yamaha","suzuki"]
    print(motorcycles)
    motorcycles.insert(0,"dycati")#在指定的元素前面插入的元素
    print(motorcycles)
    del motorcycles[0] #删除指定元素
    print(motorcycles)
    '''POP()方法删除元素并接着使用'''
    motorcycles = ["honda","yamaha","suzuki"]
    print(motorcycles)
    popdel = motorcycles.pop()# 删除列表最后一条元素,并把值赋给popdel这个变量
    print(motorcycles) #打印列表
    print(popdel) #打印取出的变量值
    motorcycles = ["honda","yamaha","suzuki"]
    first_ownde = motorcycles.pop(0) #弹出列表第一个元素,并赋值first_ownde
    print("the first motocrcle i owned was a " + first_ownde + ".")
    print(motorcycles)
    '''根据值删除元素'''
    motorcycles = ["honda","yamaha","suzuki"]
    print(motorcycles)
    motorcycles.remove("yamaha")#根据值删除指定的列表元素
    print(motorcycles)
    '''列表的排序'''

    cars=["bwm","audi","toyota","subaru"]
    print(cars)
    cars.sort()#列表永久排序
    print(cars)
    cars.sort(reverse=True)#列表永久排序降序得参数
    print(cars)
    '''临时排序展示不影响列表顺序'''
    print(sorted(cars))#临时排序展示不影响列表顺序
    print(sorted(cars,reverse=True))#临时排序展示不影响列表顺序,传入降序参数
    '''倒着打印列表'''
    print(cars)
    cars.reverse()#让列表得顺序相反,是相反不是按字母排序
    print(cars)
    '''确定列表的长度'''
    a=len(cars)
    print(a)
     
  • 相关阅读:
    MySQL索引原理
    MyBatis执行流程的各阶段介绍
    实现单栈实现支持getMin的栈
    缓存LRU算法——使用HashMap和双向链表实现
    Hystrix资源隔离
    各种负载均衡策略-图解
    接口调用超时的实现原理
    Spring Bean生命周期的各阶段介绍
    TAR命令详解 复习
    INT MOD
  • 原文地址:https://www.cnblogs.com/upuser/p/13139852.html
Copyright © 2011-2022 走看看