>>> f=open('hello.py')
>>> f.readline()
'#!/usr/bin/python2.5\n'
>>> f.readline()
'print "hello.word!"\n'
>>> f.readline()
'\n'
>>> f.readline()
''
>>> for i in open('hello.py'):
... print(i)
...
#!/usr/bin/python2.5
print "hello.word!"
>>> for i in open('hello.py').readlines():
... print i
...
#!/usr/bin/python2.5
print "hello.word!"
>>> for i in range(5): ... print(i) ...
>>> L=[0,1,2,3,4] >>> I=iter(L) >>> I.next() 0 >>> I.next() 1 >>> I.next() 2 >>> I.next() 3 >>> I.next() 4 >>> I.next()
Traceback (most recent call last): File "<stdin>", line 1, in <module> StopIteration
>>> L=[x+10 for x in range(10)] >>> L
>>> res=[] >>> for x in range(10): ... res.append(x+10) ... >>> res [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
root@10.1.6.200:python# vim 3.py
#!/usr/bin/python2.5 for i in 'hello': #序列里的字符串 print i, y = [1,2,3,4,5,6] #列表 for i in y: print i,
root@10.1.6.200:python# python 3.py
h e l l o 1 2 3 4 5 6
root@10.1.6.200:python# vim 3.py
#!/usr/bin/python2.5 x='hello' for i in range(len(x)): print x[i] y = [1,2,3,4,5,6] for i in range(len(y)): print y[i],
root@10.1.6.200:python# python 3.py
h e l l o 1 2 3 4 5 6
root@10.1.6.200:python# vim 5.py
#!/usr/bin/python2.5
z = {1:'a',2:'b',3:'c'}
for i in z:
print z[i]
root@10.1.6.200:python# python 5.py
a b c
root@10.1.6.200:python# cat 5.py
#!/usr/bin/python2.5
z = {1:'a',2:'b',3:'c'}
print z.items()
for m,n in z.items():
print m,n
root@10.1.6.200:python# python 5.py
[(1, 'a'), (2, 'b'), (3, 'c')] 1 a 2 b 3 c
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有