zoukankan      html  css  js  c++  java
  • 2-11

    字典

    '''
    字典操作
    字典是一种key-value的数据类型,使用就像我们上学用的字典,通过笔划、字母来查对应页的详细内容。
    
    
    '''
    
    #语法
    info = {
            'stu1101': 'test1',
            'stu1102': 'test2',
            'stu1103': 'test3'
            }
    print(info)
    print(type(info))
    print(info['stu1101'])
    
    '''
    字典的特性:
    dict是无序的
    key必须是唯一的,so天生去重
    
    '''
    
    #修改
    info['stu1101'] = 'test11'
    print(info)
    
    #添加
    info['stu1104'] = 'test4'
    print(info)
    
    #删除方法一
    del info['stu1101']
    print(info)
    
    #删除方法二
    info.pop('stu1102')
    
    #随机删除
    info.popitem()
    
    #查找
    info = {
            'stu1101': 'test1',
            'stu1102': 'test2',
            'stu1103': 'test3'
            }
    
    print(info.get('stu1104'))
    print(info.get('stu1103'))
    
    #判断值在不在字典里
    print('stu1104' in info)
    print('stu1103' in info)
    
    
    '''
    多级字典嵌套及操作
    
    
    '''
  • 相关阅读:
    多进程 与并发
    socket之 udp用法 dns 多道 进程
    粘包
    socket tcp
    数据集特点
    secureCRT
    算法
    auto-encoder小记
    pytorch dataloader num_workers
    CNN试验记录
  • 原文地址:https://www.cnblogs.com/python-abc/p/12021808.html
Copyright © 2011-2022 走看看