Life is short, you need Python

Python - dictionary

1.Difinition

DictTest = {"Key1":"Value1","Key2":"Value2","Key3":"Value3"}

Note:
  1)it is included by"{}"
  2)it is one to one relationship
  3)format:"key":"value"
  4)Divied by comma

  5)key: Case senstive

 

2.Usage
1)single

>>DictTest["key"]
Value

2)>>print DictTest.items()---------Transfer to List

>>print DictTest.items()
[(
'Key1','Value1'),('Key2','Value2'),('Key3','Value3')]

Like:

"%s=%s" % (k, v) for k, v in DictTest.items()

 

3.Update

>>DictTest["key"]=NewVaule

 

4.Delete

>>del DictTest["Key"]

 

 

 

posted @ 2010-08-19 10:11  runfox545  阅读(233)  评论(0编辑  收藏  举报
白月黑羽 Python教程 白月黑羽Python