zoukankan      html  css  js  c++  java
  • python日记(四)字典的常见用法

    #author:ne_zha
    #dictionary
    
                feng_shen_bang ={
                    1:'哪吒',
                    2:'雷震子',
                    3:'杨戬'
                
                }
                print(feng_shen_bang[1])
                print(feng_shen_bang)
                
                #dictionary的三种删除方式:
                #feng_shen_bang.clear()
                print(feng_shen_bang.pop(2))
                print(feng_shen_bang.popitem())
                print(feng_shen_bang)
                
                
                feng_shen_bang ={
                    1:'哪吒',
                    2:'雷震子',
                    3:'杨戬'
                }
                #合并,更新
                xi_rou_ji ={
                    4:'孙悟空',
                    5:'猪八戒'
                }
                
                feng_shen_bang.update(xi_rou_ji)
                print(feng_shen_bang)
                
                
                print(feng_shen_bang.items())
                #返回字典中的所有值
                print(feng_shen_bang.values())
                #返回字典中的所有键
                print(feng_shen_bang.keys())
                
                
                #fromkeys用法:
                seq = ('name', 'age', 'sex')
                dict = dict.fromkeys(seq)
                print("New Dictionary : %s" %  str(dict))
                dict = dict.fromkeys(seq, 10)
                print("New Dictionary : %s" %  str(dict))
                
                dict['name'] ="ne_zha"
                print(dict)
                
                c = dict.fromkeys([6,7,8],[1,{"name":"alex"},444])
                print(c)
                c[7][0]=2
                print(c)
                c[7][1]['name'] = "Jack Chen"
                print(c)
  • 相关阅读:
    第一个java程序
    Java安装
    Maven安装
    Effective Java 3
    gateway + jwt 网关认证
    idea的使用
    线程池的使用
    服务注册发现Eureka
    zookeeperAPI的常用方法
    sss
  • 原文地址:https://www.cnblogs.com/ne-zha/p/7160632.html
Copyright © 2011-2022 走看看