![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
应用实例
lht1977
这个作者很懒,什么都没留下…
展开
-
装饰器实现密码验证
db_pw={'程序1':"123",'程序2':"222",'程序3':"333"}def program_select(prog_name): def decorator_func(original_func): def wrapper_func(*args,**kwargs): i=1 while i<4: my_pw=input('请输入密码:') if原创 2022-01-20 10:27:15 · 109 阅读 · 0 评论 -
验证身份证的合规性
'''身份证的判定规则1.1.1 地址码规则: 地址码长6位 以数字1-9开头1.1.2 年份码规则: 年份码长4位 以数字18,19或20开头1.1.3 月份码规则: 月份码长2位,介于01-12之间1.1.4 日期码规则: 日期码长2位,介于01-31之间 根据前位月份不同,后位日期有不同建制条件 闰年2月29天,平年2月28天(闰年:能被4整除但不能被100整除的年份为普通闰年) 大月31天(1,3,5,7,8,10,12) 小月30天(2,4,6,9,11原创 2021-01-24 12:06:17 · 470 阅读 · 0 评论 -
2021-01-23
石头,剪刀,布游戏#石头、剪刀、布 游戏 如果想要退出,可输入’q'import randommachine=['石头','剪刀','布' ]money=10while True: my_choice=input("请输入你的选择(石头、剪刀、布):") machine_choice=random.choice(machine) if my_choice=='q': print("拜拜!") break elif my_choice原创 2021-01-23 11:09:09 · 75 阅读 · 0 评论 -
实现GOTO语句功能
要安装两个库:goto,label安装方法:pip install goto-statementpip install labelimport randomimport goto,labeldef random_number(): my_number=random.randint(1,11) return my_number@goto.with_gotodef print_message(): ran_num1=random.randint(1,11) if原创 2020-10-29 20:40:52 · 183 阅读 · 0 评论 -
MySQL用int型存储IP地址
insert into t_ip(ip) values (inet_aton(“192.168.14.112”));select * from t_ip;select inet_ntoa(ip) from t_ip;原创 2020-08-27 13:04:04 · 265 阅读 · 0 评论 -
python pip生成库列表文件
1.命令行键入: pip freeze > newrequire.txt (将其放入工程文件中)2.通过以下命令安装相应包:pip install -r newrequire.txt原创 2020-08-20 11:17:22 · 788 阅读 · 0 评论 -
python 包
批量统计字符个数from collections import Counterall_words=['python','jiango','jiango','java','python','jiango','python','java','jiango']cnt=Counter(all_words)cntCounter({‘python’: 3, ‘jiango’: 4, ‘java’: 2})原创 2020-08-20 09:49:12 · 163 阅读 · 0 评论 -
python字典操作
dict.setdefault(‘hometown’,‘JiLin’)通过setdefault追加数据时,键值如存在不会覆盖原值,如不存在追加新值。为字典设置默认值:from collections import defaultdictdict1=defaultdict(lambda:'default value')dict1...原创 2020-08-20 09:46:46 · 76 阅读 · 0 评论 -
Python 装饰器应用之登录密码
#装饰器 实现不同部门对应不同登录密码departments={"QQ":"Q","PP":"P","SS":"S"}def department(dept): def password_check(func): def wrapper(*args): temp_pw=input("请输入密码:") my_dept=dept if my_dept not in departments.keys():原创 2020-08-13 16:06:06 · 142 阅读 · 0 评论 -
map运算结果做list转换后,原数据不可重复使用
原创 2020-08-13 15:44:28 · 107 阅读 · 0 评论 -
XX.sort()与sorted(XX)区别
原创 2020-08-12 15:38:04 · 294 阅读 · 0 评论 -
Python 求偶数实例
求0-100间的偶数for循环一for i in range(100): if i%2==0: print(i)for循环二for i in range(0,100,2): print(i)推导式[print(i) for i in range(0,100,2)]filterprint(list(filter(lambda x:x%2==0,range(100))))原创 2020-08-11 15:08:55 · 1965 阅读 · 0 评论 -
Python各项辅助设置
功能辅助设置1.Jupyter Notebook 不使用print时多行输出:#Jupyter notebook输出改善from IPython.core.interactiveshell import InteractiveShellInteractiveShell.ast_node_interactivity="all"t1=1t2=2t1t2原创 2020-08-11 14:44:35 · 178 阅读 · 0 评论 -
Python 占位符的使用
Python 点位符的使用三种方式:#占位符的使用name="张三"age=22school="苏州大学"height=1.784message1="我叫%s,来自于%s,今年%d岁,身高为:%.2f米。"%(name,school,age,height)print("message1-->",message1)message2="我叫{0},来自于{1},今年{2}岁,身高为:{3}米.今年在{1}加入了中国共产党。".format(name,school,age,format(h原创 2020-08-11 14:19:47 · 635 阅读 · 0 评论 -
Python 生成任意长度随机密码
Python 生成任意长度随机密码在这里插入代码片#创建随机密码def random_characters(pass_len,my_class="a"): ''' pass_len:代表生成随机字符的长度 my_class:随机字符的构成分类 a: 字母(大小写)+数字+特殊符号 u:大写字母 l:小写字母 n:数字 ''' import random原创 2020-08-11 13:39:33 · 1098 阅读 · 0 评论 -
Python输出CSV乱码
Python输出CSV乱码只需要将encoding=‘utf-8’ 改为 encoding=‘utf-8-sig’my_df.to_csv("D:\\temp\\"+datetime.datetime.now().strftime('%Y%m%d%H%M%S')+".csv",encoding='utf-8-sig')原创 2020-08-11 10:13:06 · 180 阅读 · 0 评论 -
Python 时间装饰器代码
import timedef timer(func): def wrapper(): start=time.time() func() end=time.time() return print(end-start) return wrapper@timerdef main(): x=0 for i in range(100000000): x=x+i print(x)原创 2020-08-11 10:15:16 · 132 阅读 · 0 评论