Created
December 19, 2018 03:07
-
-
Save caoya171193579/20e24b722347c73927ec17b91aa38177 to your computer and use it in GitHub Desktop.
入门
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
迭代遍历、 变量序列 | |
偏移指数(索引): | |
 | |
 | |
遍历字典: | |
 | |
代码执行: | |
root@kali:~/xuexi# python 5.py | |
8 | |
1 | |
2 | |
6 | |
只打印出了字典z 的keys 值. 键 | |
 | |
代码执行: | |
root@kali:~/xuexi# python 6.py | |
999 | |
111 | |
222 | |
333 | |
这样打印出来了values 值。 | |
################################################### | |
 | |
root@kali:~/xuexi# python 6.py | |
999 | |
111 | |
222 | |
333 | |
[(8, 999), (1, 111), (2, 222), (6, 333)] | |
运用了参数 .items() , 返回z 的键值(key:value),转换成元祖的列表。 | |
元祖拆分: | |
>>> l=[1,2,3,'a','b'] | |
>>> l | |
[1, 2, 3, 'a', 'b'] | |
>>> a,b,c,d,e=l | |
>>> l | |
[1, 2, 3, 'a', 'b'] | |
>>> a,b,c,d,e | |
(1, 2, 3, 'a', 'b') | |
遍历字典,键值对: | |
 | |
代码执行: | |
root@kali:~/xuexi# python 6.py | |
999 | |
111 | |
222 | |
333 | |
8 | |
999 | |
1 | |
111 | |
2 | |
222 | |
6 | |
333 | |
for o,b in z.items(): | |
print o | |
print b | |
 | |
root@kali:~/xuexi# python 6.py | |
8 999 | |
1 111 | |
2 222 | |
6 333 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment