zoukankan      html  css  js  c++  java
  • python第四讲

    列表的排序
    
      升序:从小到大的排序
    
      降序:从大到小的排序
    
    示例:
    num_list = [120,250,11,44,77,45,22,390]
    num_list.sort() # 升序 - 从小到大
    print(num_list) # 对列表本身做了修改
    num_list.sort(reverse=True)#降序 为False#升序
    print(num_list)
    
      反转
    
    print(num_list[::-1])
    print(num_list)
    
    num_list.reverse() # 修改原列表
    print(num_list)
    
    元组
    
    元组()括号 - tuple
    
    可以查;没有增删改
    
    有序,以,分隔成员。成员值可以重复
    
    my_tuple = ()#空元组
    
    my_tuple2 = (18,22,33,45,60,70)
    print(my_tuple2[2]) # 下标取值
    
    my_tuple3 = ("hello",) # 1个值记得加逗号,
    print(my_tuple3)
    
    字典
    
    字典 dict  dictionary
    
    无序   key名唯一,常用字符串。 值可以是任意的数据类型。 key:value
    
    示例:dog_info = {
    "name": "陈钱罐",
    "sex": "",
    "age": "3个月",
    "type": "串串",
    "owner":"陈多多"
    }
    my_dict = {} # 空字典
    print(dog_info)
    
    print(dog_info["age"]) # 键名 key
    # print(dog_info["parent"]) # KeyError: 'parent'
    print(dog_info.get("age")) # 字典.get(键名)获取
    print(dog_info.get("parent")) # None
    
    添加、修改键值对。
    如果键名不存在于字典当中,那就是添加键值对。
    如果键名存在于字典当中,那就是修改键对应的值。
    
    #修改
    dog_info["age"] = "3个半月"
    print(dog_info)
    #新增
    dog_info["father"] = "金毛"
    print(dog_info)
    
    添加字典2到字典1:字典1.update(字典2)
    dog_other_info = {"color":"香槟色","size":"50cm"}
    dog_info.update(dog_other_info)
    print(dog_info)
    
    # 删除
    # del dog_info["father"]
    # print(dog_info)
    dog_info.pop("father")
    prindog_info.update(dog_other_info)
    print(dog_info)t(dog_info)
    
    字典里面,可以成员是字典吗?可以成员是列表吗
    
    dog_info["other_info"] = dog_other_info
    print(dog_info)
    
    # # 键 名
    # keys = dog_info.keys()
    # # list() 转换成列表数据类型
    # all_keys = list(keys)
    # print(all_keys)
    
    # # 值
    # values = dog_info.values()
    # # list() 转换成列表数据类型
    # all_values = list(values)
    # print(all_values)
    
    # 键值对
    items = dog_info.items()
    # list() 转换成列表数据类型
    all_items = list(items)
    print(all_items)
    
    list_aa = ["ssss",11,22,11,22,"hello"]
    # 去重
    set_aa = set(list_aa)
    # 转成列表
    print(list(set_aa))
    
    if条件语句
    
    看到冒号自动缩进。
    if 条件1:
    条件1为真时,执行的代码。
    
    
    if 条件1:
    条件1为真时,执行的代码。
    else:
    条件1不满足的时候,执行的代码。干的事情。
    
    
    if 条件1:
    条件1为真时,执行的代码。
    elif 条件2:
    条件2为真时,执行的代码
    elif 条件3:
    条件3为真时,执行的代码
    else:
    条件1不满足的时候,执行的代码。干的事情
    
    
    如果大于60分,就及格!
    如果小于60分,通宵敲代码
    
    if int(score) > 60:
    print("及格!")
    else:
    print("通宵敲代码!")
    
    如果分数在85到100之间;评分A
    如果分数在75到85之间;评分B
    如果分数在60到75之间;评分C
    其他评分D
    
    if 85 <= int(score) <= 100:
    print("A")
    elif 75 <= int(score) < 85:
    print("B")
    elif 60 <= int(score) < 75:
    print("C")
    else:
    print("D")
    
    debug调试
    
    你想在哪里让程序中断执行,由你自己来控制它的执行
    
    起始位置
    
    取消断点
    
    运行小虫子
    
    点击左下角取消断点
  • 相关阅读:
    2017ccpc全国邀请赛(湖南湘潭) E. Partial Sum
    Codeforces Round #412 C. Success Rate (rated, Div. 2, base on VK Cup 2017 Round 3)
    2017 中国大学生程序设计竞赛 女生专场 Building Shops (hdu6024)
    51nod 1084 矩阵取数问题 V2
    Power收集
    红色的幻想乡
    Koishi Loves Segments
    Wood Processing
    整数对
    Room and Moor
  • 原文地址:https://www.cnblogs.com/zhang-ping1205/p/12968341.html
Copyright © 2011-2022 走看看