zoukankan      html  css  js  c++  java
  • the day of python learning(字典)

    #数据类型划分:可变数据类型,不可变数据类型
    """
    不可变数据类型:元祖,bool,int,str 可哈希
    可变数据类型:list,dict,set 不可哈希
    dict key 必须是不可变数据类型,可哈希
    value:任意数据类型
    dict 优点:二分查找去查询
    存储大量的关系型数据
    特点:无序的
    """
    dic1 = {"age":18, "name":'ren','sex':'male'}
    #字典的增加
    #dic1['high'] = 185 #没有键值对,添加
    #dic1['age'] = 16 #如果有键,则值覆盖

    #dic1.setdefault('weight') #有键值对,不做任何改变,没有才添加
    # dic1.setdefault('weight',150)
    # dic1.setdefault('name','二哥')
    # print(dic1)

    #字典的删除
    # print(dic1.pop('age')) #有返回值,按键去删除
    # print(dic1.pop('二哥',None))#可设置返回值
    # print(dic1)
    #
    # print(dic1.popitem())#随机删除 有返回值 元组里面是删除的键值
    # print(dic1)

    # del dic1['name1']
    # print(dic1)#会报错
    # del dic1
    # print(dic1)
    #
    # dic1.clear()#清空字典

    #字典的修改
    # dic1['age'] = 16
    # dic = {'name':'jin','age': 18, 'sex':'male'}
    # dic2 = {'name':'alex','weight':75}
    # dic2.update(dic)
    # print(dic)
    # print(dic2)

    #字典的查找
    # print(dic1.keys(),type(dic1.keys()))
    # print(dic1.values())
    # print(dic1.items())

    #for i in dic1:
    # print(i)
    # for i in dic1.keys():
    # print(i)
    #结果一样,直接for i in dic1:

    # for i in dic1.values():
    # print(i)

    # a,b = 1,2
    # print(a,b)
    #
    # a = 1
    # b = 2
    # a,b = b,a
    # print(a,b)
    # a,b = [1,2],[2,3]
    # print(a,b)
    #
    # for k,v in dic1.items():
    # print(k,v)
    #
    # v1 = dic1['name']
    # print(v1)
    #
    # v2 = dic1['name1']#报错
    # print(v2)
    #
    # print(dic1.get('name1','没有这个键'))

    #字典的嵌套
    # dic = {
    # 'name':['alex','wusir','taibai'],
    # 'py9':{
    # 'time':'1213',
    # 'learn_money':19800,
    # 'addr':'CBD'
    # },
    # 'age':21
    # }
    # dic['age'] = 56
    # print(dic['name'])
    # dic['name'].append('renxin')
    # print(dic)
    # l = [1,2,'wusir']
    # l[2] = l[2].upper()
    # dic['name'][1] = dic['name'][1].upper()
    # print(dic)
    #
    #
    # """female:6"""
    # dic['py9']['female'] = 6
    # print(dic)



    #输入一组数字。将其打印出数字的个数,包括连接的整数
    info = input('>>>').strip()
    for i in info:
    if i.isalpha():
    info = info.replace(i," ")
    l = info.split()
    print(len(l))
     
  • 相关阅读:
    Js原型对象理解
    Garbage In Garbage Out
    JournalNode的作用
    SecondaryNameNode 的作用
    Hive Map数据长尾问题
    Hive基本操作
    Hadoop中NameNode的工作机制
    技术架构分析与架构分析
    Sqoop报错Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
    项目管理PMP相关
  • 原文地址:https://www.cnblogs.com/wai-xin-ren/p/9498503.html
Copyright © 2011-2022 走看看