1、创建python代码,testread()file.py;
2、编写python代码,
import re
def getFileContent(str):
str_value = str
len_str_value = len(str_value)
print(str_value)
print(len_str_value)
len_capital = len(re.compile(r'[A-Z]').findall(str_value))
print(u'大写字母有%d个'%len_capital)
len_lowercase = len(re.compile(r'[a-z]').findall(str_value))
print(u'小写字母有%d个'%len_lowercase)
len_num = len(re.compile(r'\d').findall(str_value))
print(u'数字有%d个'%len_num)
len_others = len_str_value -len_capital-len_lowercase-len_num
print(u'其他的字符有%d个'%len_others)
dict1 = {'capital':len_capital,'lowercase':len_lowercase,'others':len_others,'num':len_num}
return dict1
if __name__ == '__main__':
str = open('D:\\test.txt','r',encoding='UTF-8').read().replace('\t','').replace('\n','').replace(' ','').replace('space','')
print(getFileContent(str))
3、右击‘在终端中运行Python文件’;
4、查看运行结果,满足需求;