2021年5月13日

python-生成器,闭包,装饰器

摘要: 生成器第一种方式:a = (i for i in range(10))next(a)或者for循环取数第二种:函数内有yield,yield相当于两步:1、程序停止,2、return yield后边的值例如:def fib4(): print(" start ") a, b = 0, 1 for i 阅读全文

posted @ 2021-05-13 22:13 ClarenceSun 阅读(37) 评论(0) 推荐(0) 编辑

python-单向链表

摘要: # coding:utf-8class Node(object): def __init__(self, elem): self.elem = elem self.next = Noneclass SingleLinkList(object): def __init__(self, node=Non 阅读全文

posted @ 2021-05-13 20:06 ClarenceSun 阅读(47) 评论(0) 推荐(0) 编辑

python中的列表操作效率

摘要: # coding:utf-8from timeit import Timerdef test1(): li = [] for i in range(10000): li.append(i)def test2(): li = [] for i in range(10000): li = li + [i 阅读全文

posted @ 2021-05-13 20:03 ClarenceSun 阅读(214) 评论(0) 推荐(0) 编辑

python的栈--先进后出,就像杯子

摘要: # coding = utf-8class Stack(object): """栈""" def __init__(self): self.__list = [] def push(self, item): """添加一个元素item到栈顶""" self.__list.append(item) d 阅读全文

posted @ 2021-05-13 19:58 ClarenceSun 阅读(93) 评论(0) 推荐(0) 编辑

导航