随笔分类 -  Python进阶

摘要:list derivatives & dict deconstruction ebb = dict(zip('abcde', (11, 22, 11, 33, 22))) print(ebb) print([k for k, v in ebb.items() if v == 11]) filter 阅读全文
posted @ 2022-02-28 16:54 ascertain 阅读(23) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2022-02-28 14:30 ascertain 阅读(17) 评论(0) 推荐(0) 编辑
摘要:lru_cache import functools, time @functools.lru_cache(maxsize=128, typed=False) def b(x, y, z=3): time.sleep(2) return x + y print(b(5, 6)) print('~' 阅读全文
posted @ 2022-02-27 23:40 ascertain 阅读(44) 评论(0) 推荐(0) 编辑
摘要:import inspect def b(x, y: int = 5, *args, z, t=55, **kwargs) -> int: return x + y signature = inspect.signature(b) print(signature) print(signature.p 阅读全文
posted @ 2022-02-27 21:32 ascertain 阅读(91) 评论(0) 推荐(0) 编辑
摘要:打印Full binary tree: import math def reveal(vail: list | tuple): """ 利用Python居中打印 :param vail: :return: """ length = len(vail) height = math.ceil(math. 阅读全文
posted @ 2022-02-26 00:20 ascertain 阅读(34) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2022-02-26 00:04 ascertain 阅读(32) 评论(0) 推荐(0) 编辑
摘要:import datetime, multiprocessing, logging, time, threading from concurrent import futures FORMAT = '%(asctime)-9s [%(processName)-10s %(process)6d] %( 阅读全文
posted @ 2022-02-25 23:52 ascertain 阅读(53) 评论(0) 推荐(0) 编辑
摘要:import threading, time, logging, random, datetime, multiprocessing FORMAT = '%(asctime)-15s %(process)d %(lineno)-3s [%(threadName)-11s %(thread)6d] % 阅读全文
posted @ 2022-02-25 22:37 ascertain 阅读(64) 评论(0) 推荐(0) 编辑
摘要:import time, logging, typing, threading, random, datetime FORMAT = '{asctime} {levelname} {process} {processName} {threadName} {thread} {lineno}> {mes 阅读全文
posted @ 2022-02-25 21:49 ascertain 阅读(90) 评论(0) 推荐(0) 编辑
摘要:import time, logging, typing, threading, random, datetime FORMAT = '{asctime} {levelname} {process} {processName} {threadName} {thread} {message}' log 阅读全文
posted @ 2022-02-25 19:31 ascertain 阅读(71) 评论(0) 推荐(0) 编辑
摘要:消费速度 > 生产速度 import threading, time, logging, random FORMAT = '%(asctime)-15s [%(threadName)-11s %(thread)6d] %(message)s' logging.basicConfig(format=F 阅读全文
posted @ 2022-02-25 15:52 ascertain 阅读(165) 评论(0) 推荐(0) 编辑
摘要:import threading, logging logging.basicConfig(format='%(asctime)-15s [%(threadName)s %(thread)d] %(message)s', level=logging.INFO, datefmt='%F %T') de 阅读全文
posted @ 2022-02-25 12:41 ascertain 阅读(52) 评论(0) 推荐(0) 编辑
摘要:从上述报错,可知int类参数必须是 str, bytes, bytearray, int, float 五种类型 int() 可接受两个参数 base默认是10进制 无参 -> zero 第一参数为 number类型 TypeError 不能带明确的base, 即base就是默认10进制 可将flo 阅读全文
posted @ 2022-02-25 11:23 ascertain 阅读(1038) 评论(0) 推荐(0) 编辑
摘要:10 二进制前面 加 - 而已 由于Python number没有范围限制, 但是负数一定是补码表示, 正数前面有无限0, 负数前面有无限1 5 ==> (0)(infinite) 0101 -5 ==> (1)(infinite) 1011 以 四字节 为例, 将 -10 => 补码, 采用 & 阅读全文
posted @ 2021-10-20 16:42 ascertain 阅读(829) 评论(0) 推荐(0) 编辑
摘要:下个月的同天 def same_day_of_next_month(obj: datetime.date): def last_day_of_current_month(_obj: datetime.date): if _obj.month == 12: first_day_of_next_mont 阅读全文
posted @ 2021-04-21 18:51 ascertain 阅读(36) 评论(0) 推荐(0) 编辑
摘要:"," 每三位分割 '{:,}'.format(88888888888888) for align,text in zip('<^>',['left','right','right']): print('{0:{fill}{align}16}'.format(text,fill=align,alig 阅读全文
posted @ 2021-04-12 16:22 ascertain 阅读(128) 评论(0) 推荐(0) 编辑
摘要:Python内置的json模块提供了非常完善的Python对象到JSON格式的转换。 json.dumps() 将Python中的对象转换为JSON中的字符串对象json.loads() 将JSON中的字符串对象转换为Python中的对象 通过一种简单的方式,用lambda方式来转换任意一个类对象为 阅读全文
posted @ 2021-01-11 15:29 ascertain 阅读(884) 评论(0) 推荐(0) 编辑
摘要:class B: def __setattr__(self,key,value): pass raise NotImplementedError 类方法__setattr__覆盖父类方法后,如果为pass, raise NotImplementedError之类的,则实例不能设置任何属性 pass不 阅读全文
posted @ 2020-11-14 13:55 ascertain 阅读(176) 评论(0) 推荐(0) 编辑
摘要:判断list包含关系 a = [1, 2, 3, 4, 5] b = [3, 4, 5, 3] if [v for v in b if v not in a]: print('a doesn\'t comprise b') else: print('a comprise b') 采用列表解析式 a 阅读全文
posted @ 2020-11-11 14:54 ascertain 阅读(75) 评论(0) 推荐(0) 编辑
摘要:内层函数没有引用外层函数局部变量,dir()是不会显示的 def b(a): def p(): print('function p dir ->',dir()) p() print('function b dir ->',dir()) b(2) def b(a): def p(): nonlocal 阅读全文
posted @ 2020-11-11 14:50 ascertain 阅读(152) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示