ChinaUnix.net
相关文章推荐:

python 删除字典中为None的数据

在图形安装方式下,定义步骤时,在gui.py中有如下一个字典。 stepToClass = { "language" : ("language_gui", "LanguageWindow"), "agreement" : ("agreement_gui", "AgreementWindow"), "keyboard" : ("keyboard_gui", "KeyboardWindow"), "mouse" : ("mouse_gui", "MouseWindow"), "welcome" : ("welcome_gui", "WelcomeWindow"), "installtype" : ("installpath_gui", "InstallPathWindow"), "zfcp...

by 适兕 - Python文档中心 - 2008-11-29 15:40:52 阅读(1882) 回复(0)

相关讨论

http://blog.sina.com.cn/s/blog_5c6760940100bmg5.html 当然说字典,那也就有一些常用方法 ------------------------清除------------------------ clear()方法,将字典所有内容清除: >>> d = {'age' : 12, 'name' : 'bob'} >>> d {'age': 12, 'name': 'bob'} >>> d.clear() >>> d {} 有人可能会问为什么不直接d={}? 看下面的例子: >>> d = {'age' : 12, 'name' : 'bob'} >>> x = d >>> d = {} >>> x {'age': 12, 'name': 'bob'}...

by hkebao - Python文档中心 - 2009-04-29 10:58:13 阅读(1358) 回复(0)

列表和元组有几处重要的区别。列表元素用中括号( [ ])包裹,元素的个数及元素的值可 以改变。元组元素用小括号(( ))包裹,不可以更改(尽管他们的内容可以)。元组可以看成是 只读的列表。通过切片运算( [ ] 和 [ : ] )可以得到子集,这一点与字符串的使用方法一样。 >>> aList = [1, 2, 3, 4] >>> aList [1, 2, 3, 4] >>> aList[0] 1 >>> aList[2:] [3, 4] >>> aList[:3] [1, 2, 3] >>> aList[1] = 5 >>> aList [1, 5, 3, 4] 元组...

by kinganeng - Python文档中心 - 2009-04-15 16:42:15 阅读(1350) 回复(0)

常见的字典对象常量和操作 操作 解析 d1 = {} d2 = {'spam':2, 'eggs':3} d3 = {'food':{'ham':1,'egg':2}} d2['eggs'],d3['food']['ham'] d2.has_key('eggs'), d2.keys(), d2.values() len(d1) d2[key] = new del d2[key] 空的字典 两项的字典 嵌套 通过键索引 方法:成员关系测试, 键的列表, 值得列表,等等 长度(所存储的项的数目) 添加/改变, 删除 基本操作 >>> d2 = {'spam':2,'ham':1,'eggs':3} >>>...

by lvDbing - Python文档中心 - 2008-09-05 13:37:58 阅读(1353) 回复(0)

if pairs.has_key( "word" ): print """

Your word is: %s

""" \ % cgi.escape( pairs[ "word" ][0] ) pairs["word"][0]是啥意思,怎样解释?

by yjgyjg1997 - Python - 2007-03-30 17:12:29 阅读(2977) 回复(2)
by 寂寞烈火 - Python - 2009-01-08 14:31:45 阅读(2895) 回复(2)

python学习(1)-字典(Dictionary) 字典(Dictionary)是一种映射结构的数据类型,由无序的“键-值对”组成。字典的键必须是不可改变的类型,如:字符串,数字,tuple;值可以为任何python数据类型。 1、新建字典 >>> dict1={} #建立一个空字典 >>> type(dict1) 2、增加字典元素:两种方法 >>> dict1['a']=1 #第一种 >>> dict1 {'a': 1} #第二种:setdefault方法 >>> dict1.setdefault('b',2) 2 >>> dict1 {'a'...

by didonglin - Python文档中心 - 2009-04-28 13:19:48 阅读(1456) 回复(0)

看到很多关于python介绍的文章,说它功能很强大,代码写起来又简单。于是今天就打算学习了一下。在使用字典的时候有点小问题。 eg: [gan@localhost py]$ cat my_dict.py #!/usr/bin/python# Filename: my_dict.pyvdict={ "jack@hotmail.com":"newworld", "tom@hotmail.com":"second", "abc@163.com":"123456", "zwp@126.com":"kown123" }for email, pwd in vdict.items(): print "Email: %s pa...

by g_hk - Python文档中心 - 2008-12-09 18:28:59 阅读(2380) 回复(0)

字典(Dictionary)是一种映射结构的数据类型,由无序的“键-值对”组成。字典的键必须是不可改变的类型,如:字符串,数字,tuple;值可以为任何python数据类型。 1、新建字典 >>> dict1={} #建立一个空字典 >>> type(dict1) 2、增加字典元素:两种方法 >>> dict1['a']=1 #第一种 >>> dict1 {'a': 1} #第二种:setdefault方法 >>> dict1.setdefault('b',2) 2 >>> dict1 {'a': 1, 'b': 2}...

by walkingmen - Python文档中心 - 2008-04-20 14:37:19 阅读(1337) 回复(0)

数据输入结束,一个循环以后想删除输入txt文件的数据,如何删除呢?

by aphra - Python - 2008-09-08 21:54:14 阅读(2346) 回复(6)

Normal 0 7.8 磅 0 2 false false false MicrosoftInternetExplorer4 st1\:*{behavior:url(#ieooui) } /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso...

by oychw - Python文档中心 - 2009-08-16 15:49:01 阅读(1108) 回复(0)