
python程序
Noiccy
记录学习过程、学习心得;
欢迎交流,欢迎指导
展开
-
Python小程序
输入1-127的ASCII,并输出对应字符#! usr/bin/env/ python# _*_ coding:utf-8 _*_#输入1-127的ASCII,并输出对应字符for i in range(1,127): print('ASCII'+str(i)+'对应的字符是:'+chr(i),'\n')注:chr()函数:将ASCII码转化成对应的字符 ord()函...原创 2018-05-17 21:17:32 · 1263 阅读 · 0 评论 -
Python练习4:装饰器
#1、编写装饰器,为函数加上认证的功能def decorator(func): def inner(*args, **kwargs): name = input('用户名:').strip() password = input('密码:') if name == 'Noiccy' and password == '111111': ...原创 2019-01-18 18:39:45 · 505 阅读 · 0 评论 -
Python练习2:函数
斐波那契数列def fab(n): if n == 1 or n == 2: return 1 else: return fab(n-2)+fab(n-1)while True: n = input('请输入查询的数字:') if not n.isdigit(): n = input('输入有误,请重新输入查...原创 2019-01-12 21:56:50 · 329 阅读 · 0 评论 -
Python练习1:循环、字符串、列表
Day1输出九九乘法表print('九九乘法表')for i in range(1, 10): # i表示行 for j in range(1, i+1): # j表示列 if i == j: print('%d✖️%d = %-2d\t' % (j, i, j * i)) else: ...原创 2019-01-11 22:07:38 · 1489 阅读 · 0 评论 -
转化任意时区的任意时间为timestamp
#!/usr/bin/env python#_*_ coding:utf-8 _*___author__ = 'Noiccy''''description:时间转换'''from datetime import datetime, timezone, timedeltaimport time, re#输入日期时间、时区,输出timestampdef to_timestamp(d...原创 2018-09-10 16:57:07 · 1758 阅读 · 0 评论 -
实现一个FIFO的dict
#!/usr/bin/env python#_*_ coding:utf-8 _*___author__ = 'Noiccy''''description:实现一个FIFO的dict'''from collections import OrderedDictclass LastUpdatedOrderedDict(OrderedDict): """docstring fo...原创 2018-09-11 14:34:07 · 314 阅读 · 0 评论 -
利用定制类生成URL
__getattr__(self):调用属性或者方法,如果属性不存在也不会报错__call__(self):对实例进行调用__str__()返回用户看到的字符串,而__repr__()返回程序开发者看到的字符串,也就是说,__repr__()是为调试服务的#!/usr/bin/env python#_*_ coding:utf-8 _*___author__ = 'Noiccy...原创 2018-08-23 20:35:53 · 545 阅读 · 0 评论 -
文档测试doctest及常见问题
#!/usr/bin/env python#_*_ coding:utf-8 _*_author = 'Noiccy''''description:文档测试'''def fact(n): ''' Calculate 1*2*...*n >>> fact(1) 1 >>> fact(10) 362...原创 2018-08-30 17:05:38 · 1298 阅读 · 0 评论 -
Python练习3:路径操作
'''description: 找出指定目录及子目录中文件名含有某元素的文件,并移动/复制到指定目录'''import os, shutil# shutil.copy()# shutil.move()def find_all(topdir, pattern): for root, dirs, files in os.walk(topdir): fo...原创 2019-01-14 17:03:31 · 897 阅读 · 0 评论