zoukankan      html  css  js  c++  java
  • Python学习第五篇——如何访问字典

     1 # the example_1 aim to tell how to use dctionary,and how to access list or dictionary
     2 infos={"first_name":"jack","last_name":"mole","age":20,"city":"lendon"}
     3 for  info  in infos:
     4     print(str(infos[info]))
     5 # example2 aim to how to access dictionary's key and value
     6 friends_num = {"wang":8,"li":0,"jack":3,"mole":6,"zhao":5}
     7 for friend_num in friends_num:
     8     #print(friend_num)
     9     print("my friend "+friend_num+
    10         " like "+str(friends_num[friend_num]))
    11     

    1 上述代码的作用在于介绍字典的概念:字典的核心概念在于:键——值,这样的对应关系,字典并不关心键和键的顺序关系,只关心键——值的对应关系

    2 正确访问字典:字典名[键]——访问值,同时通过程序2中对键本身的访问,再次理解访问 列表或者字典时,for关键字后面的变量究竟意味着什么??

    stay foolish,stay hungry
  • 相关阅读:
    hash
    C#执行Sql事务处理
    数据库的锁表
    页面的刷新 和图片的替换
    单点登录 Webservice
    js 动态调用js文件
    .net生成EXCEL
    JS : 连续滚动
    引用指定类型的对象
    对象序列化为字符串
  • 原文地址:https://www.cnblogs.com/shaonianpi/p/9466477.html
Copyright © 2011-2022 走看看