# 分针时针秒针什么时候重合 coincide = [] for hour in range(0,12): for minute in range(0,60): for second in range(0,60): secondAngle = second*360/60 minuteAngle = int((minute+second/60)*360/60) hourAngle = int((hour+minute/60)*360/12) if secondAngle == minuteAngle == hourAngle: coincide.append('%d:%d:%d'%(hour,minute,second)) # print('%d:%d:%d,秒针%d度,分针%d度,时针%d度'%(hour,minute,second,secondAngle,minuteAngle,hourAngle)) print(coincide) # 类 class myclass(): # 私有属性--外部无法调用 __privateName = '' # 构造函数--self--类的实例:必须包含 def __init__(self): # 内部调用私有属性 self.__privateName = '' print('创建对象') # 析构函数 def __del__(self): print('释放对象') def __repr__(self): print('打印,转换') # 返回转换为字符串的输出值 def __str__(self): # 内部调用私有函数 self.__privateMethod() return str(id(self)) # 私有函数 def __privateMethod(self): print('私有函数') # 重写运算符函数 def __add__(self, other): print('加运算') # 继承--多重继承 class myChild(myclass,dict): # 重写父类构造方法 def __init__(self): print('这是mychild') print(myChild()) import glob # 文件通配符--生成文件列表 print(glob.glob('*.*')) import re # 通过正则替换所有匹配信息 print(re.sub('[1-9]','[123]','123,fdsaf123')) # 简单爬虫-->全部写入文件 import urllib.request with open('myBlog.txt','wb') as file: for line in urllib.request.urlopen('http://blog.csdn.net/yang930207/article/details/79034473'): file.write(line) # 数据压缩 import zlib,gzip,bz2,zipfile,tarfile # 性能度量 from timeit import Timer # 测试 import doctest,unittest doctest.testmod() unittest.main()
Python入门记录8
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.