python3 lib

This commit is contained in:
estomm
2020-09-24 14:53:15 +08:00
parent d186ed4acd
commit fe167ce897
38 changed files with 1424 additions and 6 deletions

View File

@@ -0,0 +1,11 @@
## itertools --- 为高效循环而创建迭代器的函数
> 算法编程这一块特别好用。
本模块标准化了一个快速、高效利用内存的核心工具集这些工具本身或组合都很有用。它们一起形成了“迭代器代数”这使得在纯Python中有可能创建简洁又高效的专用工具。
Itertool函数
itertools 配方
## functools --- 高阶函数和可调用对象上的操作
partial 对象
## operator --- 标准运算符替代函数
将运算符映射到函数
原地运算符

View File

@@ -0,0 +1,9 @@
## 概述
* 语言“核心”中的一部分的数据类型例如数字和列表。对于这些类型Python语言核心定义了文字的形式并对它们的语义设置了一些约束但没有完全定义语义。
* 内置函数和异常 --- 不需要 import 语句就可以在所有Python代码中使用的对象。
* 有一些是由语言核心定义的,但是许多对于核心语义不是必需的,并且仅在这里描述。
* 这些模块集可以不同方式分类。有些模块是用 C 编写并内置于 Python 解释器中;另一些模块则是用 Python 编写并以源码形式导入。有些模块提供专用于 Python 的接口,例如打印栈追踪信息;有些模块提供专用于特定操作系统的接口,例如操作特定的硬件;另一些模块则提供针对特定应用领域的接口,例如万维网。有些模块在所有更新和移植版本的 Python 中可用;另一些模块仅在底层系统支持或要求时可用;还有些模块则仅当编译和安装 Python 时选择了特定配置选项时才可用。

View File

@@ -0,0 +1,244 @@
## 内置函数列表
<table class="docutils align-default">
<colgroup>
<col style="width: 21%">
<col style="width: 18%">
<col style="width: 20%">
<col style="width: 20%">
<col style="width: 22%">
</colgroup>
<thead>
<tr class="row-odd"><th class="head"></th>
<th class="head"></th>
<th class="head"><p>内置函数</p></th>
<th class="head"></th>
<th class="head"></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><a class="reference internal" href="#abs" title="abs"><code class="xref py py-func docutils literal notranslate"><span class="pre">abs()</span></code></a></p></td>
<td><p><a class="reference internal" href="#delattr" title="delattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">delattr()</span></code></a></p></td>
<td><p><a class="reference internal" href="#hash" title="hash"><code class="xref py py-func docutils literal notranslate"><span class="pre">hash()</span></code></a></p></td>
<td><p><a class="reference internal" href="#func-memoryview"><code class="docutils literal notranslate"><span class="pre">memoryview()</span></code></a></p></td>
<td><p><a class="reference internal" href="#func-set"><code class="docutils literal notranslate"><span class="pre">set()</span></code></a></p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#all" title="all"><code class="xref py py-func docutils literal notranslate"><span class="pre">all()</span></code></a></p></td>
<td><p><a class="reference internal" href="#func-dict"><code class="docutils literal notranslate"><span class="pre">dict()</span></code></a></p></td>
<td><p><a class="reference internal" href="#help" title="help"><code class="xref py py-func docutils literal notranslate"><span class="pre">help()</span></code></a></p></td>
<td><p><a class="reference internal" href="#min" title="min"><code class="xref py py-func docutils literal notranslate"><span class="pre">min()</span></code></a></p></td>
<td><p><a class="reference internal" href="#setattr" title="setattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">setattr()</span></code></a></p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#any" title="any"><code class="xref py py-func docutils literal notranslate"><span class="pre">any()</span></code></a></p></td>
<td><p><a class="reference internal" href="#dir" title="dir"><code class="xref py py-func docutils literal notranslate"><span class="pre">dir()</span></code></a></p></td>
<td><p><a class="reference internal" href="#hex" title="hex"><code class="xref py py-func docutils literal notranslate"><span class="pre">hex()</span></code></a></p></td>
<td><p><a class="reference internal" href="#next" title="next"><code class="xref py py-func docutils literal notranslate"><span class="pre">next()</span></code></a></p></td>
<td><p><a class="reference internal" href="#slice" title="slice"><code class="xref py py-func docutils literal notranslate"><span class="pre">slice()</span></code></a></p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#ascii" title="ascii"><code class="xref py py-func docutils literal notranslate"><span class="pre">ascii()</span></code></a></p></td>
<td><p><a class="reference internal" href="#divmod" title="divmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">divmod()</span></code></a></p></td>
<td><p><a class="reference internal" href="#id" title="id"><code class="xref py py-func docutils literal notranslate"><span class="pre">id()</span></code></a></p></td>
<td><p><a class="reference internal" href="#object" title="object"><code class="xref py py-func docutils literal notranslate"><span class="pre">object()</span></code></a></p></td>
<td><p><a class="reference internal" href="#sorted" title="sorted"><code class="xref py py-func docutils literal notranslate"><span class="pre">sorted()</span></code></a></p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#bin" title="bin"><code class="xref py py-func docutils literal notranslate"><span class="pre">bin()</span></code></a></p></td>
<td><p><a class="reference internal" href="#enumerate" title="enumerate"><code class="xref py py-func docutils literal notranslate"><span class="pre">enumerate()</span></code></a></p></td>
<td><p><a class="reference internal" href="#input" title="input"><code class="xref py py-func docutils literal notranslate"><span class="pre">input()</span></code></a></p></td>
<td><p><a class="reference internal" href="#oct" title="oct"><code class="xref py py-func docutils literal notranslate"><span class="pre">oct()</span></code></a></p></td>
<td><p><a class="reference internal" href="#staticmethod" title="staticmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">staticmethod()</span></code></a></p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#bool" title="bool"><code class="xref py py-func docutils literal notranslate"><span class="pre">bool()</span></code></a></p></td>
<td><p><a class="reference internal" href="#eval" title="eval"><code class="xref py py-func docutils literal notranslate"><span class="pre">eval()</span></code></a></p></td>
<td><p><a class="reference internal" href="#int" title="int"><code class="xref py py-func docutils literal notranslate"><span class="pre">int()</span></code></a></p></td>
<td><p><a class="reference internal" href="#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a></p></td>
<td><p><a class="reference internal" href="#func-str"><code class="docutils literal notranslate"><span class="pre">str()</span></code></a></p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#breakpoint" title="breakpoint"><code class="xref py py-func docutils literal notranslate"><span class="pre">breakpoint()</span></code></a></p></td>
<td><p><a class="reference internal" href="#exec" title="exec"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code></a></p></td>
<td><p><a class="reference internal" href="#isinstance" title="isinstance"><code class="xref py py-func docutils literal notranslate"><span class="pre">isinstance()</span></code></a></p></td>
<td><p><a class="reference internal" href="#ord" title="ord"><code class="xref py py-func docutils literal notranslate"><span class="pre">ord()</span></code></a></p></td>
<td><p><a class="reference internal" href="#sum" title="sum"><code class="xref py py-func docutils literal notranslate"><span class="pre">sum()</span></code></a></p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#func-bytearray"><code class="docutils literal notranslate"><span class="pre">bytearray()</span></code></a></p></td>
<td><p><a class="reference internal" href="#filter" title="filter"><code class="xref py py-func docutils literal notranslate"><span class="pre">filter()</span></code></a></p></td>
<td><p><a class="reference internal" href="#issubclass" title="issubclass"><code class="xref py py-func docutils literal notranslate"><span class="pre">issubclass()</span></code></a></p></td>
<td><p><a class="reference internal" href="#pow" title="pow"><code class="xref py py-func docutils literal notranslate"><span class="pre">pow()</span></code></a></p></td>
<td><p><a class="reference internal" href="#super" title="super"><code class="xref py py-func docutils literal notranslate"><span class="pre">super()</span></code></a></p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#func-bytes"><code class="docutils literal notranslate"><span class="pre">bytes()</span></code></a></p></td>
<td><p><a class="reference internal" href="#float" title="float"><code class="xref py py-func docutils literal notranslate"><span class="pre">float()</span></code></a></p></td>
<td><p><a class="reference internal" href="#iter" title="iter"><code class="xref py py-func docutils literal notranslate"><span class="pre">iter()</span></code></a></p></td>
<td><p><a class="reference internal" href="#print" title="print"><code class="xref py py-func docutils literal notranslate"><span class="pre">print()</span></code></a></p></td>
<td><p><a class="reference internal" href="#func-tuple"><code class="docutils literal notranslate"><span class="pre">tuple()</span></code></a></p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#callable" title="callable"><code class="xref py py-func docutils literal notranslate"><span class="pre">callable()</span></code></a></p></td>
<td><p><a class="reference internal" href="#format" title="format"><code class="xref py py-func docutils literal notranslate"><span class="pre">format()</span></code></a></p></td>
<td><p><a class="reference internal" href="#len" title="len"><code class="xref py py-func docutils literal notranslate"><span class="pre">len()</span></code></a></p></td>
<td><p><a class="reference internal" href="#property" title="property"><code class="xref py py-func docutils literal notranslate"><span class="pre">property()</span></code></a></p></td>
<td><p><a class="reference internal" href="#type" title="type"><code class="xref py py-func docutils literal notranslate"><span class="pre">type()</span></code></a></p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#chr" title="chr"><code class="xref py py-func docutils literal notranslate"><span class="pre">chr()</span></code></a></p></td>
<td><p><a class="reference internal" href="#func-frozenset"><code class="docutils literal notranslate"><span class="pre">frozenset()</span></code></a></p></td>
<td><p><a class="reference internal" href="#func-list"><code class="docutils literal notranslate"><span class="pre">list()</span></code></a></p></td>
<td><p><a class="reference internal" href="#func-range"><code class="docutils literal notranslate"><span class="pre">range()</span></code></a></p></td>
<td><p><a class="reference internal" href="#vars" title="vars"><code class="xref py py-func docutils literal notranslate"><span class="pre">vars()</span></code></a></p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#classmethod" title="classmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">classmethod()</span></code></a></p></td>
<td><p><a class="reference internal" href="#getattr" title="getattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">getattr()</span></code></a></p></td>
<td><p><a class="reference internal" href="#locals" title="locals"><code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code></a></p></td>
<td><p><a class="reference internal" href="#repr" title="repr"><code class="xref py py-func docutils literal notranslate"><span class="pre">repr()</span></code></a></p></td>
<td><p><a class="reference internal" href="#zip" title="zip"><code class="xref py py-func docutils literal notranslate"><span class="pre">zip()</span></code></a></p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a></p></td>
<td><p><a class="reference internal" href="#globals" title="globals"><code class="xref py py-func docutils literal notranslate"><span class="pre">globals()</span></code></a></p></td>
<td><p><a class="reference internal" href="#map" title="map"><code class="xref py py-func docutils literal notranslate"><span class="pre">map()</span></code></a></p></td>
<td><p><a class="reference internal" href="#reversed" title="reversed"><code class="xref py py-func docutils literal notranslate"><span class="pre">reversed()</span></code></a></p></td>
<td><p><a class="reference internal" href="#__import__" title="__import__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__import__()</span></code></a></p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#complex" title="complex"><code class="xref py py-func docutils literal notranslate"><span class="pre">complex()</span></code></a></p></td>
<td><p><a class="reference internal" href="#hasattr" title="hasattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">hasattr()</span></code></a></p></td>
<td><p><a class="reference internal" href="#max" title="max"><code class="xref py py-func docutils literal notranslate"><span class="pre">max()</span></code></a></p></td>
<td><p><a class="reference internal" href="#round" title="round"><code class="xref py py-func docutils literal notranslate"><span class="pre">round()</span></code></a></p></td>
<td></td>
</tr>
</tbody>
</table>
abs()
delattr()
hash()
memoryview()
set()
all()
dict()
help()
min()
setattr()
any()
dir()
hex()
next()
slice()
ascii()
divmod()
id()
object()
sorted()
bin()
enumerate()
input()
oct()
staticmethod()
bool()
eval()
int()
open()
str()
breakpoint()
exec()
isinstance()
ord()
sum()
bytearray()
filter()
issubclass()
pow()
super()
bytes()
float()
iter()
print()
tuple()
callable()
format()
len()
property()
type()
chr()
frozenset()
list()
range()
vars()
classmethod()
getattr()
locals()
repr()
zip()
compile()
globals()
map()
reversed()
__import__()
complex()
hasattr()
max()
round()

View File

@@ -0,0 +1,23 @@
## 内置常量
### False
bool 类型的假值。 给 False 赋值是非法的并会引发 SyntaxError。
### `True`
bool 类型的真值。 给 True 赋值是非法的并会引发 SyntaxError。
### `None`
NoneType 类型的唯一值。 None 经常用于表示缺少值,当因为默认参数未传递给函数时。 给 None 赋值是非法的并会引发 SyntaxError。
### `NotImplemented`
二进制特殊方法应返回的特殊值例如__eq__()、__lt__()、__add __()、__rsub__() 等表示操作没有针对其他类型实现为了相同的目的可以通过就地二进制特殊方法例如__imul __()、__ rightnd__() 等)返回。 它的逻辑值为真。
### `Ellipsis`
与省略号文字字面 “...” 相同。 特殊值主要与用户定义的容器数据类型的扩展切片语法结合使用。
### `__debug__`
如果 Python 没有以 -O 选项启动,则此常量为真值。 另请参见 assert 语句。
> 注解 变量名 NoneFalseTrue 和 __ debug__ 无法重新赋值(赋值给它们,即使是属性名,将引发 SyntaxError ),所以它们可以被认为是“真正的”常数。
### 由 `site` 模块添加的常量
site 模块(在启动期间自动导入,除非给出 -S 命令行选项)将几个常量添加到内置命名空间。 它们对交互式解释器 shell 很有用,并且不应在程序中使用。

View File

@@ -0,0 +1,331 @@
## 内置类型
主要内置类型有数字、序列、映射、类、实例和异常。
有些多项集类是可变的。 它们用于添加、移除或重排其成员的方法将原地执行,并不返回特定的项,绝对不会返回多项集实例自身而是返回 None。
## 逻辑值检测
任何对象都可以进行逻辑值的检测,以便在 if 或 while 作为条件或是作为下文所述布尔运算的操作数来使用。
* 一个对象在默认情况下均被视为真值,除非当该对象被调用时其所属类定义了 __bool__() 方法且返回 False 或是定义了 __len__() 方法且返回零。
* 下面基本完整地列出了会被视为假值的内置对象:
* 被定义为假值的常量: None 和 False。
* 任何数值类型的零: 0, 0.0, 0j, Decimal(0), Fraction(0, 1)
* 空的序列和多项集: '', (), [], {}, set(), range(0)
> 产生布尔值结果的运算和内置函数总是返回 0 或 False 作为假值1 或 True 作为真值,除非另行说明。 (重要例外:布尔运算 or 和 and 总是返回其中一个操作数。)
## 布尔运算
布尔运算,按优先级升序排列:
<table class="docutils align-default">
<colgroup>
<col style="width: 25%">
<col style="width: 62%">
<col style="width: 13%">
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>运算</p></th>
<th class="head"><p>结果:</p></th>
<th class="head"><p>注释</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">or</span> <span class="pre">y</span></code></p></td>
<td><p>if <em>x</em> is false, then <em>y</em>, else
<em>x</em></p></td>
<td><p>(1)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">and</span> <span class="pre">y</span></code></p></td>
<td><p>if <em>x</em> is false, then <em>x</em>, else
<em>y</em></p></td>
<td><p>(2)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">not</span> <span class="pre">x</span></code></p></td>
<td><p>if <em>x</em> is false, then <code class="docutils literal notranslate"><span class="pre">True</span></code>,
else <code class="docutils literal notranslate"><span class="pre">False</span></code></p></td>
<td><p>(3)</p></td>
</tr>
</tbody>
</table>
这是个短路运算符,因此只有在第一个参数为假值时才会对第二个参数求值。
这是个短路运算符,因此只有在第一个参数为真值时才会对第二个参数求值。
not 的优先级比非布尔运算符低,因此 not a == b 会被解读为 not (a == b) 而 a == not b 会引发语法错误。
## 比较运算
<table class="docutils align-default">
<colgroup>
<col style="width: 32%">
<col style="width: 68%">
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>运算</p></th>
<th class="head"><p>含义</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">&lt;</span></code></p></td>
<td><p>严格小于</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">&lt;=</span></code></p></td>
<td><p>小于或等于</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">&gt;</span></code></p></td>
<td><p>严格大于</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">&gt;=</span></code></p></td>
<td><p>大于或等于</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">==</span></code></p></td>
<td><p>等于</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">!=</span></code></p></td>
<td><p>不等于</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">is</span></code></p></td>
<td><p>对象标识</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">is</span> <span class="pre">not</span></code></p></td>
<td><p>否定的对象标识</p></td>
</tr>
</tbody>
</table>
* 除不同的数字类型外,不同类型的对象不能进行相等比较。== 运算符总有定义,但对于某些对象类型(例如,类对象),它等于 is 。
* 具有不同标识的类的实例比较结果通常为不相等,除非类定义了 `__eq__()` 方法
* 一个类实例不能与相同类或的其他实例或其他类型的对象进行排序,除非该类定义了足够多的方法,包括 `__lt__()`, `__le__()`,` __gt__()` 以及` __ge__()` (而如果你想实现常规意义上的比较操作,通常只要有` __lt__()``__eq__()` 就可以了)。
* `is``is not` 运算符无法自定义;并且它们可以被应用于任意两个对象而不会引发异常
* `in``not in`,它们被 iterable 或实现了 `__contains__() `方法的类型所支持。
## 数字类型
* 当一个二元算术运算符的操作数有不同数值类型时,"较窄"类型的操作数会拓宽到另一个操作数的类型,其中整数比浮点数窄,浮点数比复数窄。不同类型的数字之间的比较,同比较这些数字的精确值一样。
* 构造函数 `int()``float()``complex() `可以用来构造特定类型的数字。
### 算术运算
<table class="docutils align-default">
<colgroup>
<col style="width: 25%">
<col style="width: 40%">
<col style="width: 11%">
<col style="width: 24%">
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>运算</p></th>
<th class="head"><p>结果:</p></th>
<th class="head"><p>注释</p></th>
<th class="head"><p>完整文档</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">+</span> <span class="pre">y</span></code></p></td>
<td><p><em>x</em> 和 <em>y</em> 的和</p></td>
<td></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">-</span> <span class="pre">y</span></code></p></td>
<td><p><em>x</em> 和 <em>y</em> 的差</p></td>
<td></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">*</span> <span class="pre">y</span></code></p></td>
<td><p><em>x</em> 和 <em>y</em> 的乘积</p></td>
<td></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">/</span> <span class="pre">y</span></code></p></td>
<td><p><em>x</em> 和 <em>y</em> 的商</p></td>
<td></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">//</span> <span class="pre">y</span></code></p></td>
<td><p><em>x</em> 和 <em>y</em> 的商数</p></td>
<td><p>(1)</p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">%</span> <span class="pre">y</span></code></p></td>
<td><p>remainder of <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">/</span> <span class="pre">y</span></code></p></td>
<td><p>(2)</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">-x</span></code></p></td>
<td><p><em>x</em> 取反</p></td>
<td></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">+x</span></code></p></td>
<td><p><em>x</em> 不变</p></td>
<td></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">abs(x)</span></code></p></td>
<td><p><em>x</em> 的绝对值或大小</p></td>
<td></td>
<td><p><a class="reference internal" href="functions.html#abs" title="abs"><code class="xref py py-func docutils literal notranslate"><span class="pre">abs()</span></code></a></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">int(x)</span></code></p></td>
<td><p>将 <em>x</em> 转换为整数</p></td>
<td><p>(3)(6)</p></td>
<td><p><a class="reference internal" href="functions.html#int" title="int"><code class="xref py py-func docutils literal notranslate"><span class="pre">int()</span></code></a></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">float(x)</span></code></p></td>
<td><p>将 <em>x</em> 转换为浮点数</p></td>
<td><p>(4)(6)</p></td>
<td><p><a class="reference internal" href="functions.html#float" title="float"><code class="xref py py-func docutils literal notranslate"><span class="pre">float()</span></code></a></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">complex(re,</span> <span class="pre">im)</span></code></p></td>
<td><p>一个带有实部 <em>re</em> 和虚部 <em>im</em> 的复数。<em>im</em> 默认为0。</p></td>
<td><p>(6)</p></td>
<td><p><a class="reference internal" href="functions.html#complex" title="complex"><code class="xref py py-func docutils literal notranslate"><span class="pre">complex()</span></code></a></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">c.conjugate()</span></code></p></td>
<td><p>复数 <em>c</em> 的共轭</p></td>
<td></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">divmod(x,</span> <span class="pre">y)</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">(x</span> <span class="pre">//</span> <span class="pre">y,</span> <span class="pre">x</span> <span class="pre">%</span> <span class="pre">y)</span></code></p></td>
<td><p>(2)</p></td>
<td><p><a class="reference internal" href="functions.html#divmod" title="divmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">divmod()</span></code></a></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">pow(x,</span> <span class="pre">y)</span></code></p></td>
<td><p><em>x</em> 的 <em>y</em> 次幂</p></td>
<td><p>(5)</p></td>
<td><p><a class="reference internal" href="functions.html#pow" title="pow"><code class="xref py py-func docutils literal notranslate"><span class="pre">pow()</span></code></a></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">**</span> <span class="pre">y</span></code></p></td>
<td><p><em>x</em> 的 <em>y</em> 次幂</p></td>
<td><p>(5)</p></td>
<td></td>
</tr>
</tbody>
</table>
### 整型的运算
<table class="docutils align-default">
<colgroup>
<col style="width: 31%">
<col style="width: 69%">
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>运算</p></th>
<th class="head"><p>结果:</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><a class="reference internal" href="math.html#math.trunc" title="math.trunc"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.trunc(x)</span></code></a></p></td>
<td><p><em>x</em> 截断为 <a class="reference internal" href="numbers.html#numbers.Integral" title="numbers.Integral"><code class="xref py py-class docutils literal notranslate"><span class="pre">Integral</span></code></a></p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="functions.html#round" title="round"><code class="xref py py-func docutils literal notranslate"><span class="pre">round(x[,</span>
<span class="pre">n])</span></code></a></p></td>
<td><p><em>x</em> 舍入到 <em>n</em> 位小数,半数值会舍入到偶数。 如果省略 <em>n</em>,则默认为 0。</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="math.html#math.floor" title="math.floor"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.floor(x)</span></code></a></p></td>
<td><p>&lt;= <em>x</em> 的最大 <a class="reference internal" href="numbers.html#numbers.Integral" title="numbers.Integral"><code class="xref py py-class docutils literal notranslate"><span class="pre">Integral</span></code></a></p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="math.html#math.ceil" title="math.ceil"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.ceil(x)</span></code></a></p></td>
<td><p>&gt;= <em>x</em> 的最小 <a class="reference internal" href="numbers.html#numbers.Integral" title="numbers.Integral"><code class="xref py py-class docutils literal notranslate"><span class="pre">Integral</span></code></a></p></td>
</tr>
</tbody>
</table>
### 位运算
<table class="docutils align-default">
<colgroup>
<col style="width: 22%">
<col style="width: 59%">
<col style="width: 19%">
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>运算</p></th>
<th class="head"><p>结果:</p></th>
<th class="head"><p>注释</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">|</span> <span class="pre">y</span></code></p></td>
<td><p><em>x</em> 和 <em>y</em> 按位 <em class="dfn">或</em></p></td>
<td><p>(4)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">^</span> <span class="pre">y</span></code></p></td>
<td><p><em>x</em> 和 <em>y</em> 按位 <em class="dfn">异或</em></p></td>
<td><p>(4)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">&amp;</span> <span class="pre">y</span></code></p></td>
<td><p><em>x</em> 和 <em>y</em> 按位 <em class="dfn">与</em></p></td>
<td><p>(4)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">&lt;&lt;</span> <span class="pre">n</span></code></p></td>
<td><p><em>x</em> 左移 <em>n</em> 位</p></td>
<td><p>(1)(2)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">&gt;&gt;</span> <span class="pre">n</span></code></p></td>
<td><p><em>x</em> 右移 <em>n</em> 位</p></td>
<td><p>(1)(3)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">~x</span></code></p></td>
<td><p><em>x</em> 逐位取反</p></td>
<td></td>
</tr>
</tbody>
</table>
* 负的移位数是非法的,会导致引发 ValueError。
* 左移 n 位等价于不带溢出检测地乘以 pow(2, n) 。
* 右移 n 位等价于除以 pow(2, n) ,作向下取整除法。
### 整数类型的附加方法
### 浮点类型的附加方法
### 数字类型的哈希运算
## 迭代器类型
### `container.__iter__()`
返回一个迭代器对象。 该对象需要支持下文所述的迭代器协议。 如果容器支持不同的迭代类型,则可以提供额外的方法来专门地请求不同迭代类型的迭代器。 (支持多种迭代形式的对象的例子有同时支持广度优先和深度优先遍历的树结构。) 此方法对应于 Python/C API 中 Python 对象类型结构体的 tp_iter 槽位。
迭代器对象自身需要支持以下两个方法,它们共同组成了 迭代器协议:
### `iterator.__iter__()`
返回迭代器对象本身。 这是同时允许容器和迭代器配合 for 和 in 语句使用所必须的。 此方法对应于 Python/C API 中 Python 对象类型结构体的 tp_iter 槽位。
### `iterator.__next__()`
从容器中返回下一项。 如果已经没有项可返回,则会引发 StopIteration 异常。 此方法对应于 Python/C API 中 Python 对象类型结构体的 tp_iternext 槽位。
## 生成器类型
## 序列类型
### 序列类型的通用操作
## 文本序列类型
## 二进制序列类型
## 集合类型
## 映射类型
## 上下文管理器类型
## 其他内置类型

View File

@@ -0,0 +1,36 @@
## 内置异常
## 基类
下列异常主要被用作其他异常的基类。
### `exception BaseException`
所有内置异常的基类。 它不应该被用户自定义类直接继承 (这种情况请使用 Exception)。 如果在此类的实例上调用 str(),则会返回实例的参数表示,或者当没有参数时返回空字符串。
args
传给异常构造器的参数元组。 某些内置异常 (例如 OSError) 接受特定数量的参数并赋予此元组中的元素特殊的含义,而其他异常通常只接受一个给出错误信息的单独字符串。
with_traceback(tb)
此方法将 tb 设为异常的新回溯信息并返回该异常对象。 它通常以如下的形式在异常处理程序中使用:
```
try:
...
except SomeException:
tb = sys.exc_info()[2]
raise OtherException(...).with_traceback(tb)
```
raise触发一个新的异常
```
raise new_exc from original_exc
```
### `exception Exception`
所有内置的非系统退出类异常都派生自此类。 所有用户自定义异常也应当派生自此类。
### `exception ArithmeticError`
此基类用于派生针对各种算术类错误而引发的内置异常: OverflowError, ZeroDivisionError, FloatingPointError。
### `exception BufferError`
当与 缓冲区 相关的操作无法执行时将被引发。
### `exception LookupError`
此基类用于派生当映射或序列所使用的键或索引无效时引发的异常: IndexError, KeyError。 这可以通过 codecs.lookup() 来直接引发。

View File

@@ -0,0 +1,12 @@
## 常见字符串操作
## re正则表达式操作
## difflib --- 计算差异的辅助工具
## textwrap --- 文本自动换行与填充
## unicodedata --- Unicode 数据库
## stringprep --- 因特网字符串预备
## readline --- GNU readline 接口
## rlcompleter --- GNU readline 的补全函数

View File

@@ -0,0 +1,6 @@
## struct --- 将字节串解读为打包的二进制数据
此模块可以执行 Python 值和以 Python bytes 对象表示的 C 结构之间的转换。 这可以被用来处理存储在文件中或是从网络连接等其他来源获取的二进制数据。 它使用 格式字符串 作为 C 结构布局的精简描述以及与 Python 值的双向转换。
## codecs --- 编解码器注册和相关基类

View File

@@ -0,0 +1,427 @@
## datetime
有效的类型
class datetime.date
一个理想化的简单型日期,它假设当今的公历在过去和未来永远有效。 属性: year, month, and day。
class datetime.time
一个独立于任何特定日期的理想化时间,它假设每一天都恰好等于 24*60*60 秒。 (这里没有“闰秒”的概念。) 包含属性: hour, minute, second, microsecond 和 tzinfo。
class datetime.datetime
日期和时间的结合。属性year, month, day, hour, minute, second, microsecond, and tzinfo.
class datetime.timedelta
表示两个 date 对象或者 time 对象,或者 datetime 对象之间的时间间隔,精确到微秒。
class datetime.tzinfo
一个描述时区信息对象的抽象基类。 用来给 datetime 和 time 类提供自定义的时间调整概念(例如处理时区和/或夏令时)。
class datetime.timezone
一个实现了 tzinfo 抽象基类的子类,用于表示相对于 世界标准时间UTC的偏移量。
## calendar --- 日历相关函数
这个模块让你可以输出像 Unix cal 那样的日历,它还提供了其它与日历相关的实用函数。 默认情况下,这些日历把星期一当作一周的第一天,星期天为一周的最后一天(按照欧洲惯例)。
### `class calendar.Calendar(firstweekday=0)`
### `class calendar.TextCalendar(firstweekday=0)`
### `class calendar.HTMLCalendar(firstweekday=0)`
### `class calendar.LocaleTextCalendar(firstweekday=0, locale=None)`
### `class calendar.LocaleHTMLCalendar(firstweekday=0, locale=None)```
## collections --- 容器数据类型
这个模块实现了特定目标的容器以提供Python标准内建容器 dict , list , set , 和 tuple 的替代选择。
<table class="docutils align-default">
<colgroup>
<col style="width: 24%">
<col style="width: 76%">
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="#collections.namedtuple" title="collections.namedtuple"><code class="xref py py-func docutils literal notranslate"><span class="pre">namedtuple()</span></code></a></p></td>
<td><p>创建命名元组子类的工厂函数</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#collections.deque" title="collections.deque"><code class="xref py py-class docutils literal notranslate"><span class="pre">deque</span></code></a></p></td>
<td><p>类似列表(list)的容器,实现了在两端快速添加(append)和弹出(pop)</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#collections.ChainMap" title="collections.ChainMap"><code class="xref py py-class docutils literal notranslate"><span class="pre">ChainMap</span></code></a></p></td>
<td><p>类似字典(dict)的容器类,将多个映射集合到一个视图里面</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#collections.Counter" title="collections.Counter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Counter</span></code></a></p></td>
<td><p>字典的子类,提供了可哈希对象的计数功能</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#collections.OrderedDict" title="collections.OrderedDict"><code class="xref py py-class docutils literal notranslate"><span class="pre">OrderedDict</span></code></a></p></td>
<td><p>字典的子类,保存了他们被添加的顺序</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#collections.defaultdict" title="collections.defaultdict"><code class="xref py py-class docutils literal notranslate"><span class="pre">defaultdict</span></code></a></p></td>
<td><p>字典的子类,提供了一个工厂函数,为字典查询提供一个默认值</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#collections.UserDict" title="collections.UserDict"><code class="xref py py-class docutils literal notranslate"><span class="pre">UserDict</span></code></a></p></td>
<td><p>封装了字典对象,简化了字典子类化</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#collections.UserList" title="collections.UserList"><code class="xref py py-class docutils literal notranslate"><span class="pre">UserList</span></code></a></p></td>
<td><p>封装了列表对象,简化了列表子类化</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#collections.UserString" title="collections.UserString"><code class="xref py py-class docutils literal notranslate"><span class="pre">UserString</span></code></a></p></td>
<td><p>封装了列表对象,简化了字符串子类化</p></td>
</tr>
</tbody>
</table>
## collections.abc --- 容器的抽象基类
> abc = abstract base class
该模块定义了一些 抽象基类,它们可用于判断一个具体类是否具有某一特定的接口;例如,这个类是否可哈希,或其是否为映射类。
<table class="docutils align-default">
<colgroup>
<col style="width: 21%">
<col style="width: 18%">
<col style="width: 19%">
<col style="width: 42%">
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>抽象基类</p></th>
<th class="head"><p>继承自</p></th>
<th class="head"><p>抽象方法</p></th>
<th class="head"><p>Mixin 方法</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><a class="reference internal" href="#collections.abc.Container" title="collections.abc.Container"><code class="xref py py-class docutils literal notranslate"><span class="pre">Container</span></code></a></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__contains__</span></code></p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#collections.abc.Hashable" title="collections.abc.Hashable"><code class="xref py py-class docutils literal notranslate"><span class="pre">Hashable</span></code></a></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__hash__</span></code></p></td>
<td></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#collections.abc.Iterable" title="collections.abc.Iterable"><code class="xref py py-class docutils literal notranslate"><span class="pre">Iterable</span></code></a></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__iter__</span></code></p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#collections.abc.Iterator" title="collections.abc.Iterator"><code class="xref py py-class docutils literal notranslate"><span class="pre">Iterator</span></code></a></p></td>
<td><p><a class="reference internal" href="#collections.abc.Iterable" title="collections.abc.Iterable"><code class="xref py py-class docutils literal notranslate"><span class="pre">Iterable</span></code></a></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__next__</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__iter__</span></code></p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#collections.abc.Reversible" title="collections.abc.Reversible"><code class="xref py py-class docutils literal notranslate"><span class="pre">Reversible</span></code></a></p></td>
<td><p><a class="reference internal" href="#collections.abc.Iterable" title="collections.abc.Iterable"><code class="xref py py-class docutils literal notranslate"><span class="pre">Iterable</span></code></a></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__reversed__</span></code></p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#collections.abc.Generator" title="collections.abc.Generator"><code class="xref py py-class docutils literal notranslate"><span class="pre">Generator</span></code></a></p></td>
<td><p><a class="reference internal" href="#collections.abc.Iterator" title="collections.abc.Iterator"><code class="xref py py-class docutils literal notranslate"><span class="pre">Iterator</span></code></a></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">send</span></code>, <code class="docutils literal notranslate"><span class="pre">throw</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">close</span></code>, <code class="docutils literal notranslate"><span class="pre">__iter__</span></code>, <code class="docutils literal notranslate"><span class="pre">__next__</span></code></p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#collections.abc.Sized" title="collections.abc.Sized"><code class="xref py py-class docutils literal notranslate"><span class="pre">Sized</span></code></a></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__len__</span></code></p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#collections.abc.Callable" title="collections.abc.Callable"><code class="xref py py-class docutils literal notranslate"><span class="pre">Callable</span></code></a></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__call__</span></code></p></td>
<td></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#collections.abc.Collection" title="collections.abc.Collection"><code class="xref py py-class docutils literal notranslate"><span class="pre">Collection</span></code></a></p></td>
<td><p><a class="reference internal" href="#collections.abc.Sized" title="collections.abc.Sized"><code class="xref py py-class docutils literal notranslate"><span class="pre">Sized</span></code></a>,
<a class="reference internal" href="#collections.abc.Iterable" title="collections.abc.Iterable"><code class="xref py py-class docutils literal notranslate"><span class="pre">Iterable</span></code></a>,
<a class="reference internal" href="#collections.abc.Container" title="collections.abc.Container"><code class="xref py py-class docutils literal notranslate"><span class="pre">Container</span></code></a></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__contains__</span></code>,
<code class="docutils literal notranslate"><span class="pre">__iter__</span></code>,
<code class="docutils literal notranslate"><span class="pre">__len__</span></code></p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#collections.abc.Sequence" title="collections.abc.Sequence"><code class="xref py py-class docutils literal notranslate"><span class="pre">Sequence</span></code></a></p></td>
<td><p><a class="reference internal" href="#collections.abc.Reversible" title="collections.abc.Reversible"><code class="xref py py-class docutils literal notranslate"><span class="pre">Reversible</span></code></a>,
<a class="reference internal" href="#collections.abc.Collection" title="collections.abc.Collection"><code class="xref py py-class docutils literal notranslate"><span class="pre">Collection</span></code></a></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__getitem__</span></code>,
<code class="docutils literal notranslate"><span class="pre">__len__</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__contains__</span></code>, <code class="docutils literal notranslate"><span class="pre">__iter__</span></code>, <code class="docutils literal notranslate"><span class="pre">__reversed__</span></code>,
<code class="docutils literal notranslate"><span class="pre">index</span></code>, and <code class="docutils literal notranslate"><span class="pre">count</span></code></p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#collections.abc.MutableSequence" title="collections.abc.MutableSequence"><code class="xref py py-class docutils literal notranslate"><span class="pre">MutableSequence</span></code></a></p></td>
<td><p><a class="reference internal" href="#collections.abc.Sequence" title="collections.abc.Sequence"><code class="xref py py-class docutils literal notranslate"><span class="pre">Sequence</span></code></a></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__getitem__</span></code>,
<code class="docutils literal notranslate"><span class="pre">__setitem__</span></code>,
<code class="docutils literal notranslate"><span class="pre">__delitem__</span></code>,
<code class="docutils literal notranslate"><span class="pre">__len__</span></code>,
<code class="docutils literal notranslate"><span class="pre">insert</span></code></p></td>
<td><p>继承自 <a class="reference internal" href="#collections.abc.Sequence" title="collections.abc.Sequence"><code class="xref py py-class docutils literal notranslate"><span class="pre">Sequence</span></code></a> 的方法,以及 <code class="docutils literal notranslate"><span class="pre">append</span></code>, <code class="docutils literal notranslate"><span class="pre">reverse</span></code>, <code class="docutils literal notranslate"><span class="pre">extend</span></code>, <code class="docutils literal notranslate"><span class="pre">pop</span></code>, <code class="docutils literal notranslate"><span class="pre">remove</span></code>,和 <code class="docutils literal notranslate"><span class="pre">__iadd__</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#collections.abc.ByteString" title="collections.abc.ByteString"><code class="xref py py-class docutils literal notranslate"><span class="pre">ByteString</span></code></a></p></td>
<td><p><a class="reference internal" href="#collections.abc.Sequence" title="collections.abc.Sequence"><code class="xref py py-class docutils literal notranslate"><span class="pre">Sequence</span></code></a></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__getitem__</span></code>,
<code class="docutils literal notranslate"><span class="pre">__len__</span></code></p></td>
<td><p>继承自 <a class="reference internal" href="#collections.abc.Sequence" title="collections.abc.Sequence"><code class="xref py py-class docutils literal notranslate"><span class="pre">Sequence</span></code></a> 的方法</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#collections.abc.Set" title="collections.abc.Set"><code class="xref py py-class docutils literal notranslate"><span class="pre">Set</span></code></a></p></td>
<td><p><a class="reference internal" href="#collections.abc.Collection" title="collections.abc.Collection"><code class="xref py py-class docutils literal notranslate"><span class="pre">Collection</span></code></a></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__contains__</span></code>,
<code class="docutils literal notranslate"><span class="pre">__iter__</span></code>,
<code class="docutils literal notranslate"><span class="pre">__len__</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__le__</span></code>, <code class="docutils literal notranslate"><span class="pre">__lt__</span></code>, <code class="docutils literal notranslate"><span class="pre">__eq__</span></code>, <code class="docutils literal notranslate"><span class="pre">__ne__</span></code>,
<code class="docutils literal notranslate"><span class="pre">__gt__</span></code>, <code class="docutils literal notranslate"><span class="pre">__ge__</span></code>, <code class="docutils literal notranslate"><span class="pre">__and__</span></code>, <code class="docutils literal notranslate"><span class="pre">__or__</span></code>,
<code class="docutils literal notranslate"><span class="pre">__sub__</span></code>, <code class="docutils literal notranslate"><span class="pre">__xor__</span></code>, and <code class="docutils literal notranslate"><span class="pre">isdisjoint</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#collections.abc.MutableSet" title="collections.abc.MutableSet"><code class="xref py py-class docutils literal notranslate"><span class="pre">MutableSet</span></code></a></p></td>
<td><p><a class="reference internal" href="#collections.abc.Set" title="collections.abc.Set"><code class="xref py py-class docutils literal notranslate"><span class="pre">Set</span></code></a></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__contains__</span></code>,
<code class="docutils literal notranslate"><span class="pre">__iter__</span></code>,
<code class="docutils literal notranslate"><span class="pre">__len__</span></code>,
<code class="docutils literal notranslate"><span class="pre">add</span></code>,
<code class="docutils literal notranslate"><span class="pre">discard</span></code></p></td>
<td><p>继承自 <a class="reference internal" href="#collections.abc.Set" title="collections.abc.Set"><code class="xref py py-class docutils literal notranslate"><span class="pre">Set</span></code></a> 的方法以及 <code class="docutils literal notranslate"><span class="pre">clear</span></code>, <code class="docutils literal notranslate"><span class="pre">pop</span></code>, <code class="docutils literal notranslate"><span class="pre">remove</span></code>, <code class="docutils literal notranslate"><span class="pre">__ior__</span></code>, <code class="docutils literal notranslate"><span class="pre">__iand__</span></code>, <code class="docutils literal notranslate"><span class="pre">__ixor__</span></code>,和 <code class="docutils literal notranslate"><span class="pre">__isub__</span></code></p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#collections.abc.Mapping" title="collections.abc.Mapping"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mapping</span></code></a></p></td>
<td><p><a class="reference internal" href="#collections.abc.Collection" title="collections.abc.Collection"><code class="xref py py-class docutils literal notranslate"><span class="pre">Collection</span></code></a></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__getitem__</span></code>,
<code class="docutils literal notranslate"><span class="pre">__iter__</span></code>,
<code class="docutils literal notranslate"><span class="pre">__len__</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__contains__</span></code>, <code class="docutils literal notranslate"><span class="pre">keys</span></code>, <code class="docutils literal notranslate"><span class="pre">items</span></code>, <code class="docutils literal notranslate"><span class="pre">values</span></code>,
<code class="docutils literal notranslate"><span class="pre">get</span></code>, <code class="docutils literal notranslate"><span class="pre">__eq__</span></code>, and <code class="docutils literal notranslate"><span class="pre">__ne__</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#collections.abc.MutableMapping" title="collections.abc.MutableMapping"><code class="xref py py-class docutils literal notranslate"><span class="pre">MutableMapping</span></code></a></p></td>
<td><p><a class="reference internal" href="#collections.abc.Mapping" title="collections.abc.Mapping"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mapping</span></code></a></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__getitem__</span></code>,
<code class="docutils literal notranslate"><span class="pre">__setitem__</span></code>,
<code class="docutils literal notranslate"><span class="pre">__delitem__</span></code>,
<code class="docutils literal notranslate"><span class="pre">__iter__</span></code>,
<code class="docutils literal notranslate"><span class="pre">__len__</span></code></p></td>
<td><p>继承自 <a class="reference internal" href="#collections.abc.Mapping" title="collections.abc.Mapping"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mapping</span></code></a> 的方法以及 <code class="docutils literal notranslate"><span class="pre">pop</span></code>, <code class="docutils literal notranslate"><span class="pre">popitem</span></code>, <code class="docutils literal notranslate"><span class="pre">clear</span></code>, <code class="docutils literal notranslate"><span class="pre">update</span></code>,和 <code class="docutils literal notranslate"><span class="pre">setdefault</span></code></p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#collections.abc.MappingView" title="collections.abc.MappingView"><code class="xref py py-class docutils literal notranslate"><span class="pre">MappingView</span></code></a></p></td>
<td><p><a class="reference internal" href="#collections.abc.Sized" title="collections.abc.Sized"><code class="xref py py-class docutils literal notranslate"><span class="pre">Sized</span></code></a></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__len__</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#collections.abc.ItemsView" title="collections.abc.ItemsView"><code class="xref py py-class docutils literal notranslate"><span class="pre">ItemsView</span></code></a></p></td>
<td><p><a class="reference internal" href="#collections.abc.MappingView" title="collections.abc.MappingView"><code class="xref py py-class docutils literal notranslate"><span class="pre">MappingView</span></code></a>,
<a class="reference internal" href="#collections.abc.Set" title="collections.abc.Set"><code class="xref py py-class docutils literal notranslate"><span class="pre">Set</span></code></a></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__contains__</span></code>,
<code class="docutils literal notranslate"><span class="pre">__iter__</span></code></p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#collections.abc.KeysView" title="collections.abc.KeysView"><code class="xref py py-class docutils literal notranslate"><span class="pre">KeysView</span></code></a></p></td>
<td><p><a class="reference internal" href="#collections.abc.MappingView" title="collections.abc.MappingView"><code class="xref py py-class docutils literal notranslate"><span class="pre">MappingView</span></code></a>,
<a class="reference internal" href="#collections.abc.Set" title="collections.abc.Set"><code class="xref py py-class docutils literal notranslate"><span class="pre">Set</span></code></a></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__contains__</span></code>,
<code class="docutils literal notranslate"><span class="pre">__iter__</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#collections.abc.ValuesView" title="collections.abc.ValuesView"><code class="xref py py-class docutils literal notranslate"><span class="pre">ValuesView</span></code></a></p></td>
<td><p><a class="reference internal" href="#collections.abc.MappingView" title="collections.abc.MappingView"><code class="xref py py-class docutils literal notranslate"><span class="pre">MappingView</span></code></a>,
<a class="reference internal" href="#collections.abc.Collection" title="collections.abc.Collection"><code class="xref py py-class docutils literal notranslate"><span class="pre">Collection</span></code></a></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__contains__</span></code>, <code class="docutils literal notranslate"><span class="pre">__iter__</span></code></p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#collections.abc.Awaitable" title="collections.abc.Awaitable"><code class="xref py py-class docutils literal notranslate"><span class="pre">Awaitable</span></code></a></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__await__</span></code></p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#collections.abc.Coroutine" title="collections.abc.Coroutine"><code class="xref py py-class docutils literal notranslate"><span class="pre">Coroutine</span></code></a></p></td>
<td><p><a class="reference internal" href="#collections.abc.Awaitable" title="collections.abc.Awaitable"><code class="xref py py-class docutils literal notranslate"><span class="pre">Awaitable</span></code></a></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">send</span></code>, <code class="docutils literal notranslate"><span class="pre">throw</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">close</span></code></p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#collections.abc.AsyncIterable" title="collections.abc.AsyncIterable"><code class="xref py py-class docutils literal notranslate"><span class="pre">AsyncIterable</span></code></a></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__aiter__</span></code></p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#collections.abc.AsyncIterator" title="collections.abc.AsyncIterator"><code class="xref py py-class docutils literal notranslate"><span class="pre">AsyncIterator</span></code></a></p></td>
<td><p><a class="reference internal" href="#collections.abc.AsyncIterable" title="collections.abc.AsyncIterable"><code class="xref py py-class docutils literal notranslate"><span class="pre">AsyncIterable</span></code></a></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__anext__</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">__aiter__</span></code></p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#collections.abc.AsyncGenerator" title="collections.abc.AsyncGenerator"><code class="xref py py-class docutils literal notranslate"><span class="pre">AsyncGenerator</span></code></a></p></td>
<td><p><a class="reference internal" href="#collections.abc.AsyncIterator" title="collections.abc.AsyncIterator"><code class="xref py py-class docutils literal notranslate"><span class="pre">AsyncIterator</span></code></a></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">asend</span></code>, <code class="docutils literal notranslate"><span class="pre">athrow</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">aclose</span></code>, <code class="docutils literal notranslate"><span class="pre">__aiter__</span></code>, <code class="docutils literal notranslate"><span class="pre">__anext__</span></code></p></td>
</tr>
</tbody>
</table>
## heapq --- 堆队列算法
这个模块提供了堆队列算法的实现,也称为优先队列算法。
堆是一个二叉树,它的每个父节点的值都只会小于或大于所有孩子节点(的值)。它使用了数组来实现:从零开始计数,对于所有的 k ,都有 heap[k] <= heap[2*k+1] 和 heap[k] <= heap[2*k+2]。 为了便于比较,不存在的元素被认为是无限大。 堆最有趣的特性在于最小的元素总是在根结点heap[0]。
## bisect --- 数组二分查找算法
这个模块对有序列表提供了支持,使得他们可以在插入新数据仍然保持有序。对于长列表,如果其包含元素的比较操作十分昂贵的话,这可以是对更常见方法的改进。这个模块叫做 bisect 因为其使用了基本的二分bisection算法。
## array --- 高效的数值数组
此模块定义了一种对象类型,可以紧凑地表示基本类型值的数组:字符、整数、浮点数等。 数组属于序列类型,其行为与列表非常相似,不同之处在于其中存储的对象类型是受限的。 类型在对象创建时使用单个字符的 类型码 来指定。
<table class="docutils align-default">
<colgroup>
<col style="width: 14%">
<col style="width: 25%">
<col style="width: 24%">
<col style="width: 29%">
<col style="width: 9%">
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>类型码</p></th>
<th class="head"><p>C 类型</p></th>
<th class="head"><p>Python 类型</p></th>
<th class="head"><p>以字节表示的最小尺寸</p></th>
<th class="head"><p>注释</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'b'</span></code></p></td>
<td><p>signed char</p></td>
<td><p>int</p></td>
<td><p>1</p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">'B'</span></code></p></td>
<td><p>unsigned char</p></td>
<td><p>int</p></td>
<td><p>1</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'u'</span></code></p></td>
<td><p>Py_UNICODE</p></td>
<td><p>Unicode 字符</p></td>
<td><p>2</p></td>
<td><p>(1)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">'h'</span></code></p></td>
<td><p>signed short</p></td>
<td><p>int</p></td>
<td><p>2</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'H'</span></code></p></td>
<td><p>unsigned short</p></td>
<td><p>int</p></td>
<td><p>2</p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">'i'</span></code></p></td>
<td><p>signed int</p></td>
<td><p>int</p></td>
<td><p>2</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'I'</span></code></p></td>
<td><p>unsigned int</p></td>
<td><p>int</p></td>
<td><p>2</p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">'l'</span></code></p></td>
<td><p>signed long</p></td>
<td><p>int</p></td>
<td><p>4</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'L'</span></code></p></td>
<td><p>unsigned long</p></td>
<td><p>int</p></td>
<td><p>4</p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">'q'</span></code></p></td>
<td><p>signed long long</p></td>
<td><p>int</p></td>
<td><p>8</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'Q'</span></code></p></td>
<td><p>unsigned long long</p></td>
<td><p>int</p></td>
<td><p>8</p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">'f'</span></code></p></td>
<td><p>float</p></td>
<td><p>float</p></td>
<td><p>4</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'d'</span></code></p></td>
<td><p>double</p></td>
<td><p>float</p></td>
<td><p>8</p></td>
<td></td>
</tr>
</tbody>
</table>
## weakref --- 弱引用
`pass`
## types --- 动态类型创建和内置类型名称
`pass`
## copy --- 浅层 (shallow) 和深层 (deep) 复制操作
Python 中赋值语句不复制对象,而是在目标和对象之间创建绑定 (bindings) 关系。对于自身可变或者包含可变项的集合对象,开发者有时会需要生成其副本用于改变操作,进而避免改变原对象。本模块提供了通用的浅层复制和深层复制操作
```py
copy.copy(x)
返回 x 的浅层复制
copy.deepcopy(x[, memo])
返回 x 的深层复制
exception copy.error
针对模块特定错误引发
```
### 浅层复制和深层复制之间的区别仅与复合对象 (即包含其他对象的对象,如列表或类的实例) 相关:
* 一个 浅层复制 会构造一个新的复合对象,然后(在可能的范围内)将原对象中找到的 引用 插入其中。
* 一个 深层复制 会构造一个新的复合对象,然后递归地将原始对象中所找到的对象的 副本 插入。
### 深度复制操作通常存在两个问题, 而浅层复制操作并不存在这些问题:
* 递归对象 (直接或间接包含对自身引用的复合对象) 可能会导致递归循环。
* 由于深层复制会复制所有内容,因此可能会过多复制(例如本应该在副本之间共享的数据)。
### ` deepcopy()` 解决上述问题
* 保留在当前复制过程中已复制的对象的 "备忘录" memo 字典;以及
* 允许用户定义的类重载复制操作或复制的组件集合。
### 想要给一个类定义它自己的拷贝操作实现.
可以通过定义特殊方法 `__copy__()``__deepcopy__()`。 调用前者以实现浅层拷贝操作,该方法不用传入额外参数。 调用后者以实现深层拷贝操作;它应传入一个参数即 `memo` 字典。 如果 `__deepcopy__()` 实现需要创建一个组件的深层拷贝,它应当调用 `deepcopy()` 函数并以该组件作为第一个参数,而将 memo 字典作为第二个参数。
## pprint --- 数据美化输出
pprint 模块提供了“美化打印”任意 Python 数据结构的功能,这种美化形式可用作对解释器的输入。 如果经格式化的结构包含非基本 Python 类型的对象,则其美化形式可能无法被加载。 包含文件、套接字或类对象,以及许多其他不能用 Python 字面值来表示的对象都有可能导致这样的结果。
格式化后的形式会在可能的情况下以单行来表示对象,并在无法在允许宽度内容纳对象的情况下将其分为多行。 如果你需要调整宽度限制则应显式地构造 PrettyPrinter 对象。
字典在计算其显示形式前会先根据键来排序。
```py
class pprint.PrettyPrinter(indent=1, width=80, depth=None, stream=None, *, compact=False, sort_dicts=True)
pprint.pformat(object, indent=1, width=80, depth=None, *, compact=False, sort_dicts=True)
pprint.pformat(object, indent=1, width=80, depth=None, *, compact=False, sort_dicts=True)
pprint.pprint(object, stream=None, indent=1, width=80, depth=None, *, compact=False, sort_dicts=True)
pprint.isrecursive(object)
pprint.saferepr(object)
```
## reprlib --- 另一种 repr() 实现
`pass`
## enum --- 对枚举的支持
枚举是一组符号名称(枚举成员)的集合,枚举成员应该是唯一的、不可变的。在枚举中,可以对成员进行恒等比较,并且枚举本身是可迭代的。

View File

@@ -0,0 +1,316 @@
## numbers --- 数字的抽象基类
class numbers.Number
class numbers.Complex
class numbers.Real
class numbers.Rational
class numbers.Integral
## 数论与表示函数
### `math.ceil(x)`
返回 x 的上限,即大于或者等于 x 的最小整数。如果 x 不是一个浮点数,则委托 x.__ceil__(), 返回一个 Integral 类的值。
### `math.comb(n, k)`
返回不重复且无顺序地从 n 项中选择 k 项的方式总数。
当 k <= n 时取值为 n! / (k! * (n - k)!);当 k > n 时取值为零。
也称为二项式系数,因为它等价于表达式 (1 + x) ** n 的多项式展开中第 k 项的系数。
如果任一参数不为整数则会引发 TypeError。 如果任一参数为负数则会引发 ValueError。
### `math.copysign(x, y)`
返回一个基于 x 的绝对值和 y 的符号的浮点数。在支持带符号零的平台上copysign(1.0, -0.0) 返回 -1.0.
### `math.fabs(x)`
返回 x 的绝对值。
### `math.factorial(x)`
以一个整数返回 x 的阶乘。 如果 x 不是整数或为负数时则将引发 ValueError。
### `math.floor(x)`
返回 x 的向下取整,小于或等于 x 的最大整数。如果 x 不是浮点数,则委托 x.__floor__() ,它应返回 Integral 值。
### `math.fmod(x, y)`
返回 fmod(x, y) 由平台C库定义。请注意Python表达式 x % y 可能不会返回相同的结果。C标准的目的是 fmod(x, y) 完全(数学上;到无限精度)等于 x - n*y 对于某个整数 n ,使得结果具有 与 x 相同的符号和小于 abs(y) 的幅度。Python的 x % y 返回带有 y 符号的结果,并且可能不能完全计算浮点参数。 例如, fmod(-1e-100, 1e100) 是 -1e-100 但Python的 -1e-100 % 1e100 的结果是 1e100-1e-100 ,它不能完全表示为浮点数,并且取整为令人惊讶的 1e100 。 出于这个原因,函数 fmod() 在使用浮点数时通常是首选而Python的 x % y 在使用整数时是首选。
### `math.frexp(x)`
返回 x 的尾数和指数作为对``(m, e)``。 m 是一个浮点数, e 是一个整数,正好是 x == m * 2**e 。 如果 x 为零,则返回 (0.0, 0) ,否则返回 0.5 <= abs(m) < 1 。这用于以可移植方式“分离”浮点数的内部表示。
### `math.fsum(iterable)`
返回迭代中的精确浮点值。通过跟踪多个中间部分和来避免精度损失
```py
>>>
>>> sum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
0.9999999999999999
>>> fsum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
1.0
```
该算法的准确性取决于IEEE-754算术保证和舍入模式为半偶的典型情况。在某些非Windows版本中底层C库使用扩展精度添加并且有时可能会使中间和加倍导致它在最低有效位中关闭。
有关待进一步讨论和两种替代方法,参见 ASPN cookbook recipes for accurate floating point summation。
### `math.gcd(a, b)`
返回整数 a 和 b 的最大公约数。如果 a 或 b 之一非零,则 gcd(a, b) 的值是能同时整除 a 和 b 的最大正整数。gcd(0, 0) 返回 0。
### `math.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)`
若 a 和 b 的值比较接近则返回 True否则返回 False。
根据给定的绝对和相对容差确定两个值是否被认为是接近的。
rel_tol 是相对容差 —— 它是 a 和 b 之间允许的最大差值,相对于 a 或 b 的较大绝对值。例如要设置5的容差请传递 rel_tol=0.05 。默认容差为 1e-09确保两个值在大约9位十进制数字内相同。 rel_tol 必须大于零。
abs_tol 是最小绝对容差 —— 对于接近零的比较很有用。 abs_tol 必须至少为零。
如果没有错误发生,结果将是: abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol) 。
IEEE 754特殊值 NaN inf 和 -inf 将根据IEEE规则处理。具体来说 NaN 不被认为接近任何其他值,包括 NaN 。 inf 和 -inf 只被认为接近自己。
### `math.isfinite(x)`
如果 x 既不是无穷大也不是NaN则返回 True ,否则返回 False 。 (注意 0.0 被认为 是 有限的。)
### `math.isinf(x)`
如果 x 是正或负无穷大,则返回 True ,否则返回 False 。
### `math.isnan(x)`
如果 x 是 NaN不是数字则返回 True ,否则返回 False 。
### `math.isqrt(n)`
返回非负整数 n 的整数平方根。 这就是对 n 的实际平方根向下取整,或者相当于使得 a² ≤ n 的最大整数 a。
对于某些应用来说,可以更适合取值为使得 n ≤ a² 的最小整数 a ,或者换句话说就是 n 的实际平方根向上取整。 对于正数 n这可以使用 a = 1 + isqrt(n - 1) 来计算。
### `math.ldexp(x, i)`
返回 x * (2**i) 。 这基本上是函数 frexp() 的反函数。
### `math.modf(x)`
返回 x 的小数和整数部分。两个结果都带有 x 的符号并且是浮点数。
### `math.perm(n, k=None)`
返回不重复且有顺序地从 n 项中选择 k 项的方式总数。
当 k <= n 时取值为 n! / (n - k)!;当 k > n 时取值为零。
如果 k 未指定或为 None则 k 默认值为 n 并且函数将返回 n!。
如果任一参数不为整数则会引发 TypeError。 如果任一参数为负数则会引发 ValueError。
### `math.prod(iterable, *, start=1)`
计算输入的 iterable 中所有元素的积。 积的默认 start 值为 1。
当可迭代对象为空时,返回起始值。 此函数特别针对数字值使用,并会拒绝非数字类型。
### `math.remainder(x, y)`
返回 IEEE 754 风格的 x 相对于 y 的余数。对于有限 x 和有限非零 y ,这是差异 x - n*y ,其中 n 是与商 x / y 的精确值最接近的整数。如果 x / y 恰好位于两个连续整数之间,则最近的 * even* 整数用于 n 。 余数 r = remainder(x, y) 因此总是满足 abs(r) <= 0.5 * abs(y) 。
特殊情况遵循IEEE 754特别是 remainder(x, math.inf) 对于任何有限 x 都是 x ,而 remainder(x, 0) 和 remainder(math.inf, x) 引发 ValueError 适用于任何非NaN的 x 。如果余数运算的结果为零,则该零将具有与 x 相同的符号。
在使用IEEE 754二进制浮点的平台上此操作的结果始终可以完全表示不会引入舍入错误。
### `math.trunc(x)`
返回 Real 值 x 截断为 Integral (通常是整数)。 委托给 x.__trunc__()。
注意 frexp() 和 modf() 具有与它们的C等价函数不同的调用/返回模式:它们采用单个参数并返回一对值,而不是通过 '输出形参' 返回它们的第二个返回参数Python中没有这样的东西
对于 ceil() floor() 和 modf() 函数,请注意 所有 足够大的浮点数都是精确整数。Python浮点数通常不超过53位的精度与平台C double类型相同在这种情况下任何浮点 x 与 abs(x) >= 2**52 必然没有小数位。
## 幂函数与对数函数
### `math.exp(x)`
返回 e 次 x 幂,其中 e = 2.718281... 是自然对数的基数。这通常比 math.e ** x 或 pow(math.e, x) 更精确。
math.expm1(x)
返回 e 的 x 次幂减1。这里 e 是自然对数的基数。对于小浮点数 x exp(x) - 1 中的减法可能导致 significant loss of precision expm1() 函数提供了一种将此数量计算为全精度的方法:
```py
>>>
>>> from math import exp, expm1
>>> exp(1e-5) - 1 # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1(1e-5) # result accurate to full precision
1.0000050000166668e-05
```
### `math.log(x[, base])`
使用一个参数,返回 x 的自然对数(底为 e )。
使用两个参数,返回给定的 base 的对数 x ,计算为 log(x)/log(base) 。
### `math.log1p(x)`
返回 1+x (base e) 的自然对数。以对于接近零的 x 精确的方式计算结果。
### `math.log2(x)`
返回 x 以2为底的对数。这通常比 log(x, 2) 更准确。
参见 int.bit_length() 返回表示二进制整数所需的位数,不包括符号和前导零。
### `math.log10(x)`
返回 x 底为10的对数。这通常比 log(x, 10) 更准确。
### `math.pow(x, y)`
将返回 x 的 y 次幂。特殊情况尽可能遵循C99标准的附录'F'。特别是, pow(1.0, x) 和 pow(x, 0.0) 总是返回 1.0 ,即使 x 是零或NaN。 如果 x 和 y 都是有限的, x 是负数, y 不是整数那么 pow(x, y) 是未定义的,并且引发 ValueError 。
与内置的 ** 运算符不同, math.pow() 将其参数转换为 float 类型。使用 ** 或内置的 pow() 函数来计算精确的整数幂。
### `math.sqrt(x)`
返回 x 的平方根。
## 三角函数
math.acos(x)
以弧度为单位返回 x 的反余弦值。
### `math.asin(x)`
以弧度为单位返回 x 的反正弦值。
### `math.atan(x)`
以弧度为单位返回 x 的反正切值。
### `math.atan2(y, x)`
以弧度为单位返回 atan(y / x) 。结果是在 -pi 和 pi 之间。从原点到点 (x, y) 的平面矢量使该角度与正X轴成正比。 atan2() 的点的两个输入的符号都是已知的,因此它可以计算角度的正确象限。 例如, atan(1) 和 atan2(1, 1) 都是 pi/4 ,但 atan2(-1, -1) 是 -3*pi/4 。
### `math.cos(x)`
返回 x 弧度的余弦值。
### `math.dist(p, q)`
返回 p 与 q 两点之间的欧几里得距离,以一个坐标序列(或可迭代对象)的形式给出。 两个点必须具有相同的维度。
大致相当于:
sqrt(sum((px - qx) ** 2.0 for px, qx in zip(p, q)))
3.8 新版功能.
### `math.hypot(*coordinates)`
返回欧几里得范数sqrt(sum(x**2 for x in coordinates))。 这是从原点到坐标给定点的向量长度。
对于一个二维点 (x, y),这等价于使用毕达哥拉斯定义 sqrt(x*x + y*y) 计算一个直角三角形的斜边。
在 3.8 版更改: 添加了对 n 维点的支持。 之前的版本只支持二维点。
### `math.sin(x)`
返回 x 弧度的正弦值。
### `math.tan(x)`
返回 x 弧度的正切值。
角度转换
### `math.degrees(x)`
将角度 x 从弧度转换为度数。
### `math.radians(x)`
将角度 x 从度数转换为弧度。
## 双曲函数
双曲函数 是基于双曲线而非圆来对三角函数进行模拟。
### `math.acosh(x)`
返回 x 的反双曲余弦值。
### `math.asinh(x)`
返回 x 的反双曲正弦值。
### `math.atanh(x)`
返回 x 的反双曲正切值。
### `math.cosh(x)`
返回 x 的双曲余弦值。
### `math.sinh(x)`
返回 x 的双曲正弦值。
### `math.tanh(x)`
返回 x 的双曲正切值。
## 特殊函数
### `math.erf(x)`
返回 x 处的 error function 。
erf() 函数可用于计算传统的统计函数,如 累积标准正态分布
```py
def phi(x):
'Cumulative distribution function for the standard normal distribution'
return (1.0 + erf(x / sqrt(2.0))) / 2.0
```
### `math.erfc(x)`
返回 x 处的互补误差函数。 互补错误函数 定义为 1.0 - erf(x)。 它用于 x 的大值,从其中减去一个会导致 有效位数损失。
### `math.gamma(x)`
返回 x 处的 伽马函数 值。
### `math.lgamma(x)`
返回Gamma函数在 x 绝对值的自然对数。
## 常量
### `math.pi`
数学常数 π = 3.141592...,精确到可用精度。
### `math.e`
数学常数 e = 2.718281...,精确到可用精度。
### `math.tau`
数学常数 τ = 6.283185...精确到可用精度。Tau 是一个圆周常数,等于 2π圆的周长与半径之比。更多关于 Tau 的信息可参考 Vi Hart 的视频 Pi is (still) Wrong。吃两倍多的派来庆祝 Tau 日 吧!
### `math.inf`
浮点正无穷大。 (对于负无穷大,使用 -math.inf 。)相当于 float('inf') 的输出。
### `math.nan`
浮点“非数字”NaN值。 相当于 float('nan') 的输出。
## cmath --- 关于复数的数学函数
## decimal --- 十进制定点和浮点运算
## fractions --- 分数
## random --- 生成伪随机数
该模块实现了各种分布的伪随机数生成器。
几乎所有模块函数都依赖于基本函数 random() ,它在半开放区间 [0.0,1.0) 内均匀生成随机浮点数。
## statistics --- 数学统计函数
该模块提供了用于计算数字 (Real-valued) 数据的数理统计量的函数。
## 平均值以及对中心位置的评估
<table class="docutils align-default">
<colgroup>
<col style="width: 27%">
<col style="width: 73%">
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="#statistics.mean" title="statistics.mean"><code class="xref py py-func docutils literal notranslate"><span class="pre">mean()</span></code></a></p></td>
<td><p>数据的算术平均数(“平均数”)。</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#statistics.fmean" title="statistics.fmean"><code class="xref py py-func docutils literal notranslate"><span class="pre">fmean()</span></code></a></p></td>
<td><p>快速的,浮点算数平均数。</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#statistics.geometric_mean" title="statistics.geometric_mean"><code class="xref py py-func docutils literal notranslate"><span class="pre">geometric_mean()</span></code></a></p></td>
<td><p>数据的几何平均数</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#statistics.harmonic_mean" title="statistics.harmonic_mean"><code class="xref py py-func docutils literal notranslate"><span class="pre">harmonic_mean()</span></code></a></p></td>
<td><p>数据的调和均值</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#statistics.median" title="statistics.median"><code class="xref py py-func docutils literal notranslate"><span class="pre">median()</span></code></a></p></td>
<td><p>数据的中位数(中间值)</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#statistics.median_low" title="statistics.median_low"><code class="xref py py-func docutils literal notranslate"><span class="pre">median_low()</span></code></a></p></td>
<td><p>数据的低中位数</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#statistics.median_high" title="statistics.median_high"><code class="xref py py-func docutils literal notranslate"><span class="pre">median_high()</span></code></a></p></td>
<td><p>数据的高中位数</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#statistics.median_grouped" title="statistics.median_grouped"><code class="xref py py-func docutils literal notranslate"><span class="pre">median_grouped()</span></code></a></p></td>
<td><p>分组数据的中位数即第50个百分点。</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#statistics.mode" title="statistics.mode"><code class="xref py py-func docutils literal notranslate"><span class="pre">mode()</span></code></a></p></td>
<td><p>离散的或标称的数据的单个众数(出现最多的值)。</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#statistics.multimode" title="statistics.multimode"><code class="xref py py-func docutils literal notranslate"><span class="pre">multimode()</span></code></a></p></td>
<td><p>离散的或标称的数据的众数列表(出现最多的值)。</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#statistics.quantiles" title="statistics.quantiles"><code class="xref py py-func docutils literal notranslate"><span class="pre">quantiles()</span></code></a></p></td>
<td><p>将数据以相等的概率分为多个间隔。</p></td>
</tr>
</tbody>
</table>

View File

View File

View File

View File

View File

View File

View File

@@ -8,27 +8,29 @@
--------------
学习路线
### Python系列
### Python系列(一周)
python3-numpy-scipy-matplotlib-pandas
### 机器学习系列(视频教程)
### 机器学习系列(视频教程)(三周)
> 需要了解机器学习的各种工具需要的进行补充。使用python3进行编程实践。这一部分是最关键的需要按照知乎的方法进行调整学习。入门课程->模型算法->编程实践
1. 吴恩达的课程一看。跟着做做笔记。
2. 统计学习方法一看。3Blue1Brown的视频看一看。跟着做做笔记。
3. 《机器学习西瓜书》一看。跟着做做笔记。林轩田《机器学习基石》《机器学习技法》。李宏毅的《机器学习视频教程》。《机器学习实战》量子位提供的书,适合编程。
4. tensorflow教程一看实现一遍之前的算法
3. 《机器学习西瓜书》一看。跟着做做笔记。
4. 《机器学习实战》量子位提供的书,适合编程
5. tensorflow教程一看实现一遍之前的算法。
> 补充:林轩田《机器学习基石》《机器学习技法》。李宏毅的《机器学习视频教程》。
工具
* sklearn
* tensorflow
### 深度学习系列
### 深度学习系列(一周)
吴恩达的神经网络五套课程看完。
各种神经网络。
### 联邦学习系列
### 联邦学习系列(三周)
> 尝试搭建小型的联邦学习框架。寻找网络教程,完成这一块,还有很多书。
tensorflow
fate

1
张量/补充.md Normal file
View File

@@ -0,0 +1 @@
之前做过一份笔记,需要回家的时候找一下。对张量的维数的理解。