? Editing: Post:21.body Save Delete Cancel
Content changed Sign & Publish new content

Edward's Blog

Life is journey.

Follow in NewsfeedFollowing

TOC by date
TOC by tag

Latest comments:

Python学习笔记 字典dict常用操作方法实例总结

on Jul 10, 2017
tag: Python

创建一空字典
x = {}
创建包含三个项目的字典
x = {"one":1, "two":2, "three":3}
访问其中的一个元素
x['two']
返回字典中的所有键列表
x.keys()
返回字典中的所有值列表
x.values()
添加一个新的项目
x["four"]=4
修改一个字典项目
x["one"] = "uno"
删除一个字典项目
del x["four"]
复制一个字典到新的变量
y = x.copy()
清除所有字典项目
x.clear()
返回字典长度,项目个数
z = len(x)
检测字典是否包含了指定的key
z = x.has_key("one")
遍历字典中的key
for item in x.keys(): print item
遍历字典中的值列表
for item in x.values(): print item
使用if语句获取字典中相应的键值
if "one" in x:
print x['one']
if "two" not in x:
print "Two not found"
if "three" in x:
del x['three']

Read more

First Experience of Zeronet

on May 31, 2015
tag: Test

This is my first experience of Zeronet, I'm interested in this project and curious about how it will affect the Internet.

Read more
Add new post

Title

21 hours ago · 2 min read ·
3 comments

tag:
Body
Read more

Title

21 hours ago · 2 min read
tag:

0 Comments:

user_name1 day ago
Reply
Body
<< 1 >>
This page is a preview of ZeroNet. Start your own ZeroNet for complete experience. Learn More