python奇偶行 python奇偶行分开存储实现代码
为援不可图 人气:0想了解python奇偶行分开存储实现代码的相关内容吗,为援不可图在本文为您仔细讲解python奇偶行的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:python奇偶行,下面大家一起来学习吧。
例子:
1:www.qb5200.com
2:www.qb5200.com
3:www.qb5200.com
4:www.qb5200.com
5:www.qb5200.com
6:www.qb5200.com
7:www.qb5200.com
8:www.qb5200.com
9:www.qb5200.com
10:www.qb5200.com
11:www.qb5200.com
12:www.qb5200.com
13:www.qb5200.com
14:www.qb5200.com
15:www.qb5200.com
16:www.qb5200.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("jb51.txt","oushu.txt","jishu.txt")
效果图
python中%代表什么意思
求模运算,相当于mod,也就是计算除法的余数,比如5%3就得到2。
加载全部内容