Posted in Python onMarch 19, 2018
例子:
1:3water.com
2:3water.com
3:3water.com
4:3water.com
5:3water.com
6:3water.com
7:3water.com
8:3water.com
9:3water.com
10:3water.com
11:3water.com
12:3water.com
13:3water.com
14:3water.com
15:3water.com
16:3water.com
python函数代码
# -*- coding: utf-8 -*- ''' python读取文件,偶数行输出一个文件,奇数行输出一个文件 ''' def fenhang(infile,outfile,outfile1): infopen = open(infile,'r',encoding='utf-8') outopen = open(outfile,'w',encoding='utf-8') outopen1 = open(outfile1, 'w', encoding='utf-8') lines = infopen.readlines() i = 0 for line in lines: i += 1 if i % 2 == 0: outopen.write(line) else: outopen1.write(line) infopen.close() outopen.close() fenhang("3water.txt","oushu.txt","jishu.txt")
效果图
python中%代表什么意思
求模运算,相当于mod,也就是计算除法的余数,比如5%3就得到2。
python奇偶行分开存储实现代码
- Author -
为援不可图声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@