1。
-
s='hello'
-
l=[1,2,3,'a','b']
-
t=(7,8,9,'x','y')
-
for x in l:
-
print x
-
for x in range(len(s)):
-
print s[x]
-
-
-
***************************************************************
-
python 1.py
-
1
-
2
-
3
-
a
-
b
-
h
-
e
-
l
-
l
-
o
2.
-
#!/usr/bin/python
-
s='hello'
-
l=[1,2,3,'a','b']
-
t=(7,8,9,'x','y')
-
for x in l:
-
if x>=2:
-
print x
-
for x in range(len(s)):
-
print s[x]
python 1.py
2
3
a
b
h
e
l
l
o
3.显现遍历字典
-
#!/usr/bin/python
-
s='hello'
-
l=[1,2,3,'a','b']
-
t=(7,8,9,'x','y')
-
d={1:111,2:222,3:333,5:555}
-
for x in d:
-
print x
-
print d[x]
或者这样
#!/usr/bin/python
s='hello'
l=[1,2,3,'a','b']
t=(7,8,9,'x','y')
d={1:111,2:222,3:333,5:555}
for k,v in d.items():
print k
print v
*******************************
python 1.py
1
111
2
222
3
333
5
555
阅读(1198) | 评论(0) | 转发(0) |