- 1.定义 模块:用来从逻辑上组织python代码(变量,函数,类),实现一个功能,本质是.py结尾的python文件,(文件名:test.py,对应的模块名:test) 包:用来从逻辑上组织模块,本质是一个目录(必须包含init.py文件) 2.导入方法 导入单个: import module1 导入多个: import module1, module21... 1.定义 模块:用来从逻辑上组织python代码(变量,函数,类),实现一个功能,本质是.py结尾的python文件,(文件名:test.py,对应的模块名:test) 包:用来从逻辑上组织模块,本质是一个目录(必须包含init.py文件) 2.导入方法 导入单个: import module1 导入多个: import module1, module21...
- queue队列 先入先出队列 first in first out import queue q1 = queue.Queue() q1.put(1) q1.put(2) q1.put(3) print(q1.get()) print(q1.get()) print(q1.get()) # 1 2 3123456789101112 后入先出队列 last i... queue队列 先入先出队列 first in first out import queue q1 = queue.Queue() q1.put(1) q1.put(2) q1.put(3) print(q1.get()) print(q1.get()) print(q1.get()) # 1 2 3123456789101112 后入先出队列 last i...
- 定义一个装饰器 def decorator(func): def wrapper(*arg, **kwargs): print("before") ret = func(*arg, **kwargs) print("after") return ret return wrapper 123456789101112 使用示例 # -*- coding: utf-... 定义一个装饰器 def decorator(func): def wrapper(*arg, **kwargs): print("before") ret = func(*arg, **kwargs) print("after") return ret return wrapper 123456789101112 使用示例 # -*- coding: utf-...
- 导入模块 import configparser # py31 写入 config = configparser.ConfigParser() config["DEFAULT"] = { 'ServerAliveInterval': '45', 'Compression': 'yes', 'CompressionLevel': '9' } config['b... 导入模块 import configparser # py31 写入 config = configparser.ConfigParser() config["DEFAULT"] = { 'ServerAliveInterval': '45', 'Compression': 'yes', 'CompressionLevel': '9' } config['b...
- # -*- coding: utf-8 -*- # @Date : 2019-02-14 # @Author : Peng Shiyu from copy import deepcopy import numpy as np from sklearn.feature_extraction import DictVectorizer from sklearn.me... # -*- coding: utf-8 -*- # @Date : 2019-02-14 # @Author : Peng Shiyu from copy import deepcopy import numpy as np from sklearn.feature_extraction import DictVectorizer from sklearn.me...
- 基本统计(含排序) 分布/累计统计 数据特征 相关性、周期性等 数据挖掘(形成知识) 一组数据表达一个或多个含义 摘要 - 数据形成有损特征的过程 pandas库的数据排序 .sort_index()方法在指定轴上根据索引进行排序,默认升序 .sort_index(axis=0, ascending=True) .sort_values()方法在指定轴上根据... 基本统计(含排序) 分布/累计统计 数据特征 相关性、周期性等 数据挖掘(形成知识) 一组数据表达一个或多个含义 摘要 - 数据形成有损特征的过程 pandas库的数据排序 .sort_index()方法在指定轴上根据索引进行排序,默认升序 .sort_index(axis=0, ascending=True) .sort_values()方法在指定轴上根据...
- 1、call函数 class Foo(): def __init__(self): print("Foo-init") def __call__(self): print("Foo-call") f = Foo() f() # 重载了括号运算符 """ Foo-init Foo-call """12345678910111213 2、类装饰器 class De... 1、call函数 class Foo(): def __init__(self): print("Foo-init") def __call__(self): print("Foo-call") f = Foo() f() # 重载了括号运算符 """ Foo-init Foo-call """12345678910111213 2、类装饰器 class De...
- https://flask-basicauth.readthedocs.io/en/latest/ 通过Flask-BasicAuth,提供用户名密码即可实现Authentication(认证)机制 安装 pip install Flask-BasicAuth 1 代码示例 # -*- coding: utf-8 -*- # @Date : 2018-10-... https://flask-basicauth.readthedocs.io/en/latest/ 通过Flask-BasicAuth,提供用户名密码即可实现Authentication(认证)机制 安装 pip install Flask-BasicAuth 1 代码示例 # -*- coding: utf-8 -*- # @Date : 2018-10-...
- six 它是一个专门用来兼容 Python 2 和 Python 3 的库 pip install six 1 PyPI : https://pypi.org/project/six/ 文档:https://six.readthedocs.io/ github: https://github.com/benjaminp/six Python 2.7.5 >... six 它是一个专门用来兼容 Python 2 和 Python 3 的库 pip install six 1 PyPI : https://pypi.org/project/six/ 文档:https://six.readthedocs.io/ github: https://github.com/benjaminp/six Python 2.7.5 >...
- 封装 从业务逻辑中抽象对象时,赋予对象相关数据与操作,把一些数据和操作打包在一起的过程就是封装 对象的实现和使用是独立的 支持代码复用 多态 对象怎么回应一个依赖于对象类型或种类的消息 在不同情况下用一个函数名启用不同方法 灵活性 继承 ... 封装 从业务逻辑中抽象对象时,赋予对象相关数据与操作,把一些数据和操作打包在一起的过程就是封装 对象的实现和使用是独立的 支持代码复用 多态 对象怎么回应一个依赖于对象类型或种类的消息 在不同情况下用一个函数名启用不同方法 灵活性 继承 ...
- 使用functools.partial可以创建一个新的函数,这个新函数可以固定住原函数的部分参数,从而在调用时更简单。 # -*- coding: utf-8 -*- # @File : partial偏函数.py # @Date : 2018-05-30 # @Author : Peng Shiyu from functools import partial ... 使用functools.partial可以创建一个新的函数,这个新函数可以固定住原函数的部分参数,从而在调用时更简单。 # -*- coding: utf-8 -*- # @File : partial偏函数.py # @Date : 2018-05-30 # @Author : Peng Shiyu from functools import partial ...
- 代码示例 import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10] plt.figure() plt.scatter(x, y) plt.savefig("f.png") 123456789 绘制效果 代码示例 import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10] plt.figure() plt.scatter(x, y) plt.savefig("f.png") 123456789 绘制效果
- 文档:https://docs.python.org/zh-cn/3.9/library/string.html#template-strings 代码示例 from string import Template s = Template('I am ${name}') ret = s.substitute(name="Tom") print(ret) # I ... 文档:https://docs.python.org/zh-cn/3.9/library/string.html#template-strings 代码示例 from string import Template s = Template('I am ${name}') ret = s.substitute(name="Tom") print(ret) # I ...
- 文档: http://amoffat.github.io/sh/index.html 安装 pip install sh 1 简单示例 >>> import sh >>> sh.echo("hi") hi 12345 此文章中还提到了好多库和模块,都很有用: 精选26个Python实用技巧,想秀技能先Get这份技术列表!... 文档: http://amoffat.github.io/sh/index.html 安装 pip install sh 1 简单示例 >>> import sh >>> sh.echo("hi") hi 12345 此文章中还提到了好多库和模块,都很有用: 精选26个Python实用技巧,想秀技能先Get这份技术列表!...
- 第一次接触graphics库,折腾了大半天,遇到了N多问题: 问题开始: No module named 'graphics' 尝试解决,当时想,没有这个模块,那我安装一个好了,然后。。。 解决失败。继续 ... 第一次接触graphics库,折腾了大半天,遇到了N多问题: 问题开始: No module named 'graphics' 尝试解决,当时想,没有这个模块,那我安装一个好了,然后。。。 解决失败。继续 ...
上滑加载中
推荐直播
-
华为云码道 × 仓颉编程:工程化AI编码探索2026/05/27 周三 19:00-21:00
刘俊杰-华为云仓颉语言专家/李炎-华为云码道技术专家/王智鹏-OpenCangjie开源社区发起人
本场直播围绕华为云仓颉语言与华为云码道的深度结合,展示华为云智能编程从零基础到高效落地的完整生态能力。以华为云码道为引擎,仓颉语言为载体,带给大家日常提效、趣味创新到极速量产的开发体验。
回顾中
热门标签