摘要: Python 线性查找 线性查找指按一定的顺序检查数组中每一个元素,直到找到所要寻找的特定值为止。 def line_search(arr, n, x): for i in range(0, n): if arr[i] == x: return i return -1 arr=['a','b','c 阅读全文
posted @ 2019-12-07 20:56 腹肌猿 阅读(217) 评论(0) 推荐(0) 编辑
摘要: Python 二分查找 二分搜索是一种在有序数组中查找某一特定元素的搜索算法。搜索过程从数组的中间元素开始,如果中间元素正好是要查找的元素,则搜索过程结束;如果某一特定元素大于或者小于中间元素,则在数组大于或小于中间元素的那一半中查找,而且跟开始一样从中间元素开始比较。如果在某一步骤数组为空,则代表 阅读全文
posted @ 2019-12-07 20:36 腹肌猿 阅读(241) 评论(0) 推荐(0) 编辑
摘要: 方法1: (参考https://suixinblog.cn/2019/01/print-colorful.html) 使用Python中自带的print输出带有颜色或者背景的字符串 书写语法 print(\033[显示方式;前景色;背景色m输出内容\033[0m)其中,显示方式、前景色、背景色都是可 阅读全文
posted @ 2019-12-07 20:05 腹肌猿 阅读(760) 评论(0) 推荐(0) 编辑
摘要: def customer(): r="" while True: n=yield r#,接收生产者的消息,并向消费者发送r print("customer receive",n) r="ok" def produce(c): c.send(None)#第一次启动协程必须发送None值,否则报如下错误 阅读全文
posted @ 2019-12-07 01:17 腹肌猿 阅读(823) 评论(0) 推荐(0) 编辑
摘要: 安装 pip install gevent import gevent from gevent import monkey monkey.patch_all()#捕捉所有阻塞,不止接收gevent.sleep import time def f(s): print("hello %s"%s) tim 阅读全文
posted @ 2019-12-07 00:37 腹肌猿 阅读(326) 评论(0) 推荐(0) 编辑
摘要: 给定一个字典,然后计算它们所有数字值的和。 实例 1 : 使用 update() 方法,第二个参数合并第一个参数 def Merge(dict1, dict2): return(dict2.update(dict1)) # 两个字典 dict1 = {'a': 10, 'b': 8} dict2 = 阅读全文
posted @ 2019-12-06 14:59 腹肌猿 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 安装pyinstaller包 pip3 install pyinstaller 如果不行 pip3 install pyinstaller -i https://pypi.doubanio.com/simple 准备一个你要打包的.py文件,cd到该文件路径下,打开cmd 在命令行中输入: pyin 阅读全文
posted @ 2019-12-06 01:04 腹肌猿 阅读(2246) 评论(0) 推荐(0) 编辑
摘要: pip install PyInstaller 报错: 后运行: 指定安装源进行安装: pip3 install pyinstaller -i https://pypi.doubanio.com/simple 安装成功 或者这个可以试试 修改超时时间: pip --default-timeout=1 阅读全文
posted @ 2019-12-06 00:37 腹肌猿 阅读(1174) 评论(0) 推荐(0) 编辑
摘要: 在django中,访问非同源网站(协议,域名,端口号)时,会出现: 解决方案: 1.安装 django-cors-headers pip install django-cors-headers 2.修改 setting.py INSTALLED_APPS = [ ... 'corsheaders', 阅读全文
posted @ 2019-12-06 00:28 腹肌猿 阅读(200) 评论(0) 推荐(0) 编辑
摘要: 函数标注通常用于 类型提示:例如以下函数预期接受两个 int 参数并预期返回一个 int 值:```def sum_two_numbers(a: int, b: int) -> int:return a + b ->:标记返回函数注释,信息作为.__annotations__属性提供 __annot 阅读全文
posted @ 2019-11-26 21:29 腹肌猿 阅读(3566) 评论(0) 推荐(0) 编辑