易截截图软件、单文件、免安装、纯绿色、仅160KB

Python入门的36个例子 之 21

源代码下载:下载地址在这里
# 024
dict1 = {
'5064001':'Mememe',
'5064002':'tutu',
'5064003':'thrthr',
'5064004':'fofo'
}
print dict1['5064003']
# 也可以使用整型作为唯一的编号
dict2 = {
5064001:'Mememe',
5064002:'tutu',
5064003:'thrthr',
5064004:'fofo'
}
print dict2[5064003]
# 添加
dict2[5064000] = 'none'
print dict2[5064000]
del dict2[5064002]
print dict2
for ele in dict2:
print ele
for id, name in dict2.items():
print id, name

output:
thrthr
thrthr
none
{5064000: 'none', 5064001: 'Mememe', 5064003: 'thrthr', 5064004: 'fofo'}
5064000
5064001
5064003
5064004
5064000 none
5064001 Mememe
5064003 thrthr
5064004 fofo


相关文档:

MoteLab:返回串口数据处理(python)

从MoteLab返回的串口数据,包含messages.pickle文件这是MoteLab系统中串口收集数据的总和,但是这些数据需要解析后才能进行分析。下面的代码就是在python环境下提取message有效数据的代码。
使用命令 python TestOutput.py messages.pickle
生成的test.log就是获得的有效数据
返回数据的示例
1252985727.66  recei ......

Python入门的36个例子——17 Return

# 017
def lifeIsAMirror():
string = raw_input()
if string == 'I love you!':
return 'I love you, too!'
elif string == 'Fuck you!':
return ''
else:
return
# end of def
string = lifeIsAMirror()
if len(string) == 0:
print 'You have nothing.'
else: ......

学习《Python语言入门》第五章 模块

模块这东西好像没什么好讲的,无非是保存一份文件,然后在另一份文件中用import 和from ** import **(*)就行了。
这一章主要讲到了细节,导入模块Python里面是什么处理的,import 和 from ** import **有什么不一样。还有就是增加了reload()这个函数的使用说明。
以前看到哪里说尽量使用import而不要使用from ** import * ......

Python入门的36个例子 之 19

源代码下载:下载地址在这里
# 023
# Tuple(元素组)是不可变的列表
tuple1 = (1, 2, 3)
print tuple1
tuple2 = (tuple1, 4, 5, 6) # 一个元素组可以作为另外一个元素组的元素
print tuple2 # 并且能够在存储的时候保持原始的逻辑关系
for ele in tuple2:
print ele
print '\n'
for ele in tuple2[0]:
pr ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号