随笔分类 -  Python

摘要:类的继承 基本概念 面向对象三要素之一,继承 Inheritance 人类和猫类都继承自动物类。 个体继承自父母,继承了父母的一部分特征,但也可以有自己的个性。 在面向对象的世界中,从父类继承,就可以直接拥有父类的属性和方法,这样可以减少代码,多复用。子类可以自定义自己的属性性和方法。 不用继承的例 阅读全文 »
posted @ 2022-04-28 18:48 何时&明月 阅读(54) 评论(0) 推荐(0) 编辑
摘要:面向对象 语言的分类 面向机器: 抽象成机器指令,机器容易理解 代表:汇编语言 面向过程: 做一件事情,排出个步骤,第一步干什么,第二步干什么,如果出现情况A,做什么处理,如果出现了情况B,做什么处理。 问题规模小,可以步骤化,按部就班处理 面向对象OOP: 随着计算机需要解决的问题的规模扩大,情况 阅读全文 »
posted @ 2022-04-26 10:55 何时&明月 阅读(139) 评论(0) 推荐(0) 编辑
摘要:树 vertex 顶点 element 元素 node 节点 二叉树 二叉树性质 插入排序 origin = [1, 9, 8, 5] nums = [None] + origin length = len(nums) count_move = 0 for i in range(2, length) 阅读全文 »
posted @ 2022-04-22 09:59 何时&明月 阅读(26) 评论(0) 推荐(0) 编辑
摘要:高阶函数 sorted函数 def sort(iterable, *, key=None, reverse=False): newlist =[] for x in iterable: for i,y in enumerate(newlist): if x > y: newlist.insert(i 阅读全文 »
posted @ 2022-04-22 09:59 何时&明月 阅读(18) 评论(0) 推荐(0) 编辑
摘要:柯里化 装饰器 import datetime import time def logger(fn): def wrapper(*args, **kwargs): print('before +++++++++++++++++++') start = datetime.datetime.now() 阅读全文 »
posted @ 2022-04-22 09:59 何时&明月 阅读(17) 评论(0) 推荐(0) 编辑
摘要:函数调用 函数调用执行流程 递归Recursion 斐波那契数列 RecursionError Ipython 栈空间3000 ,python 栈空间1000 sys.getrecursionLimit() pro = 1 def fn1(n): # 3 ; 2 1 if n == 1 : # re 阅读全文 »
posted @ 2022-04-22 09:58 何时&明月 阅读(38) 评论(0) 推荐(0) 编辑
摘要:生成器 #F44336 generator def foo(): print(1) yield 2 # 暂停当前函数执行 print(3) yield 4 print(5) return 6 # 函数返回,yield结束 yield 7 def counter(): i = 0 while True 阅读全文 »
posted @ 2022-04-22 09:58 何时&明月 阅读(29) 评论(0) 推荐(0) 编辑
摘要:函数返回值 函数作用域 #F44336 嵌套函数 def outer3(): print('~~~~~~~~~~') o = 65 def inner(): o = 97 print("inner", chr(o), o) inner() print("outer", chr(o), o) x = 阅读全文 »
posted @ 2022-04-22 09:57 何时&明月 阅读(22) 评论(0) 推荐(0) 编辑
摘要:内建函数 迭代器不一定是生成器,但生成器一定是迭代器 #F44336 木桶效应,以最短的为准 阅读全文 »
posted @ 2022-04-22 09:55 何时&明月 阅读(24) 评论(0) 推荐(0) 编辑
摘要:选择排序 num_list = [ [1, 9, 8, 5, 6, 4], [1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1] ] nums = num_list[1] length = len(nums) for i in range( 阅读全文 »
posted @ 2022-04-22 09:55 何时&明月 阅读(41) 评论(0) 推荐(0) 编辑
摘要:函数 def add(x,y): print(x,y) return x + y 函数参数 缺省值参数要往后放 可变参数 def sum1(*iterable): # 可变形参,接收 0-n 个 print(type(iterable), iterable) s = 0 for x in itera 阅读全文 »
posted @ 2022-04-22 09:55 何时&明月 阅读(78) 评论(0) 推荐(0) 编辑
摘要:dict 去重,存放后面的值。key不可为list,value可为list。 dict() 里使用这种写法语法不对,需标识符,‘1’ 和 1 不是标识符。 set 设置,如果没kv对,则使用当前这个key构建一个kv对,value没写用 None并返回当前的value值;如果有kv对,返回原本的va 阅读全文 »
posted @ 2022-04-22 09:54 何时&明月 阅读(22) 评论(0) 推荐(0) 编辑
摘要:ascii码 a = '\x0d\x0a\x09' a '\r\n\t' x = 'abc' y = x.encode() # x必须是字符串类型 x,y ('abc', b'abc') y.decode() # bytes类型对象.decode() 二进制 => str 'abc' hex(123 阅读全文 »
posted @ 2022-04-22 09:52 何时&明月 阅读(54) 评论(0) 推荐(0) 编辑
摘要:质数又称素数。一个大于1的自然数,除了1和它自身外,不能被其他自然数整除的数叫做质数;否则称为合数(规定1既不是质数也不是合数)。 import datetime n = 100000 count =1 ops=0 start = datetime.datetime.now() for x in r 阅读全文 »
posted @ 2022-04-22 09:52 何时&明月 阅读(116) 评论(0) 推荐(0) 编辑
摘要:可变 : list bytearray set set 定义时不能出现 list bytearray dict set 类型 (不可hash) 解释器每次运行拿到的hash值不一样 去重时,hash值一样,就不添加 阅读全文 »
posted @ 2022-04-22 09:52 何时&明月 阅读(22) 评论(0) 推荐(0) 编辑
摘要:字符串 0x31 ==> 0011 0001 49 0x41 ==> 0100 0001 65 0x61 ==> 0110 0001 97 a = 'abc' a = f'{a}+++' # 差值 3.6版本以上 a ## 'abc+++' range(5) # 惰性 range(0, 5) lis 阅读全文 »
posted @ 2022-04-22 09:50 何时&明月 阅读(41) 评论(0) 推荐(0) 编辑
摘要:逻辑运算符:与或非 and or not and 如果前面的表达式等价为False,后面就没有必要计算了,这个逻辑表达式最终一定等价为False or 如果前面的表达式等价为True,后面没有必要计算了,这个逻辑表达式最终一定等价为True 赋值运算符:先算右边后再赋值给左边变量 成员运算符: in 阅读全文 »
posted @ 2022-04-21 17:29 何时&明月 阅读(52) 评论(0) 推荐(0) 编辑
摘要:闭包 #F44336 内部函数用到了外部函数的自由变量,就形成了闭包 nonlocal语句 默认值的作用域 .__defaults__ 记录当前缺省值 __defaults__ 可以修改 不可变类型 += ,地址修改,覆盖 可变类型 +=,地址不变,就地修改 变量名解析原则LEGB #F44336 阅读全文 »
posted @ 2022-04-20 18:14 何时&明月 阅读(35) 评论(0) 推荐(0) 编辑
摘要:标准库 datetime time datetime - datetime ⇒ timedelta datetime + - timedelta ⇒ datetime datetime + datetime ⇒ 错误 #F44336 列表解析式 [print("{}*{}={:<3}{}".form 阅读全文 »
posted @ 2022-04-20 18:05 何时&明月 阅读(33) 评论(0) 推荐(0) 编辑
摘要:修改 pip 为国内源 pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ 或 pip config set global.index-url https://pypi.tuna.tsinghua.edu.c 阅读全文 »
posted @ 2022-04-20 18:03 何时&明月 阅读(26) 评论(0) 推荐(0) 编辑

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