1.字符串操作:
number=‘441801199710232652‘ print(‘身份证号码:‘+number) sr="" for i in number[0:2]: sr=sr+i print(sr+":所在省市") sr="" for i in number[2:4]: sr=sr+i print(sr+":所在地区") sr="" for i in number[4:6]: sr=sr+i print(sr+":所在县区") sr="" for i in number[6:14]: sr=sr+i print(sr+":出生日期:"+sr[0:4]+"年"+sr[4:6]+"月"+sr[6:8]+"日") sr="" for i in number[14:16]: sr=sr+i print(sr+":户口所归属的派出所") print(number[16]+":性别(男为奇数,女为偶数)") print(number[17]+":校验位")
s=‘‘ demo=‘Tom小学生‘ print(‘明文:‘+demo) for j in demo: s=s+chr(ord(j)+3) print(‘加密后:‘+s) ss=‘‘ for k in s: ss=ss+chr(ord(k)-3) print(‘解密后:‘+ss)
href=‘http://news.gzcc.cn/html/xiaoyuanxinwen/index.html‘ for o in range(1,11):#254 if(o==1): print(href) else: print(‘http://news.gzcc.cn/html/xiaoyuanxinwen/‘+str(o)+‘.html‘)
2.英文词频统计预处理
song = song.lower() x=‘,...\n?!‘ for xx in x: song=song.replace(xx,‘ ‘) print(song.split(‘ ‘)) for n in song.split(‘ ‘): print(n+‘:‘+str(song.count(n)))
3.文件操作
text1=open(‘Tom.txt‘,‘r‘,encoding=‘utf-8‘) text1=text1.read() text11=‘‘ for t in text1: text11=text11+chr(ord(t)+3) text2=open(‘Tom1.txt‘,‘a‘,encoding=‘utf-8‘) text2=text2.write(text11)
text=open(‘gril.txt‘,‘r‘,encoding=‘utf-8‘) text=text.read() x=",?!." for xx in x: text1=text.replace(xx,‘ ‘) print(text1) text2=open(‘gril1.txt‘,‘a‘,encoding=‘utf-8‘) text2.write(text1)
4.函数定义
def encryption(text): s=‘‘ for i in text: s=s+chr(ord(i)+3) return s
def decrypt(text): s = ‘‘ for i in text: s = s + chr(ord(i)-3) return s
def readFile(filePath): file=open(filePath,‘r‘,encoding=‘utf-8‘) return file.read()
原文:https://www.cnblogs.com/zpfs/p/10498232.html