摘要:
创建字典1. { }>>> dic={'name':'pmghong','age':'22','gender':'male'}>>> dic['name']'pmghong' 2. 使用工厂方法dict( )fdict=dict(['x',1],['y',2]) 3. 内建方法:fromkeys( ) ,字典中的元素具有相同的值,默认为Noneddict={}.fromkeys(('x' 阅读全文
posted @ 2015-06-14 09:14
51runsky
阅读(108)
评论(0)
推荐(0)
摘要:
列表类似于C++中的vector,C语言中的数组,用于存储顺序结构 创建列表(list) a=['1','2'] 用[]括起来,表示一个list,中间的各个元素可以是任何类型,用逗号分隔。 列表结构 list函数 拆分字符串成列表 >>> list('chongshi') ['c', 'h', 'o', 'n', 'g', 's', '... 阅读全文
posted @ 2015-06-14 09:12
51runsky
阅读(220)
评论(0)
推荐(0)
摘要:
tuple性质tuple是常量list。tuple不能pop,remove,insert等方法tuple用()表示,如a=(0,1,2,3,4),括号可以省略tuple可以用下标返回元素或者子tupletuple 可以用于多个变量的赋值 >>> a,b = (1,2) >>> print a,b 1 2 >>> t = (1,2) >>> a,b = t >>> prin... 阅读全文
posted @ 2015-06-14 09:08
51runsky
阅读(139)
评论(0)
推荐(0)
摘要:
字符串格式化 实例: >>> 'Price of eggs: $%d' %42 'Price of eggs: $42' >>> 'Hexadcimal price of eggs: %x' %42 # 16进制 'Hexadcimal price of eggs: 2a' >>> from math import pi >>> ... 阅读全文
posted @ 2015-06-14 09:07
51runsky
阅读(139)
评论(0)
推荐(0)
浙公网安备 33010602011771号