标签:
1、巧用for循环计数,将文件每10行写到另一个文件,每遍历一行i就加1
with open(‘/etc/passwd‘) as f1, open(‘/tmp/passwd‘,‘w‘) as f2:
i = 0
for line in f1:
i += 1
if i % 10 == 0:
print line,
f2.write(line)
2、打印图形
count = 1
while count < 6:
print count * ‘*‘
count += 1
for line in range(1,6):
print line * ‘*‘
for number in range(1,6):
if number % 2 == 0:
print 5 * ‘+‘
else:
print 5 * ‘@‘
结果:
* ** *** **** ***** * ** *** **** ***** @@@@@ +++++ @@@@@ +++++ @@@@@
标签:
原文地址:http://www.cnblogs.com/huangweimin/p/5540987.html