2. 内置函数
***********

Python 解释器内置了很多函数和类型，您可以在任何时候使用它们。以下按字
母表顺序列出它们。

+---------------------+-------------------+--------------------+------------------+----------------------+
|                     |                   | 内置函数           |                  |                      |
+=====================+===================+====================+==================+======================+
| "abs()"             | "dict()"          | "help()"           | "min()"          | "setattr()"          |
+---------------------+-------------------+--------------------+------------------+----------------------+
| "all()"             | "dir()"           | "hex()"            | "next()"         | "slice()"            |
+---------------------+-------------------+--------------------+------------------+----------------------+
| "any()"             | "divmod()"        | "id()"             | "object()"       | "sorted()"           |
+---------------------+-------------------+--------------------+------------------+----------------------+
| "ascii()"           | "enumerate()"     | "input()"          | "oct()"          | "staticmethod()"     |
+---------------------+-------------------+--------------------+------------------+----------------------+
| "bin()"             | "eval()"          | "int()"            | "open()"         | "str()"              |
+---------------------+-------------------+--------------------+------------------+----------------------+
| "bool()"            | "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()"        |                      |
+---------------------+-------------------+--------------------+------------------+----------------------+
| "delattr()"         | "hash()"          | "memoryview()"     | "set()"          |                      |
+---------------------+-------------------+--------------------+------------------+----------------------+

abs(x)

   返回一个数的绝对值。实参可以是整数或浮点数。如果实参是一个复数，返
   回它的模。

all(iterable)

   如果 *iterable* 的所有元素为真（或迭代器为空），返回 "True" 。等价
   于:

      def all(iterable):
          for element in iterable:
              if not element:
                  return False
          return True

any(iterable)

   如果*iterable*的任一元素为真则返回``True``。如果迭代器为空，返回
   ``False``。等价于:

      def any(iterable):
          for element in iterable:
              if element:
                  return True
          return False

ascii(object)

   就像函数 "repr()"，返回一个对象可打印的字符串，但是 "repr()" 返回的
   字符串中非 ASCII 编码的字符，会使用 "\x"、"\u" 和 "\U" 来转义。生成
   的字符串和 Python 2 的 "repr()" 返回的结果相似。

bin(x)

   将一个整数转变为一个前缀为“0b”的二进制字符串。结果是一个合法的
   Python 表达式。如果 *x* 不是 Python 的 "int" 对象，那它需要定义
   "__index__()"  方法返回一个整数。一些例子：

   >>> bin(3)
   '0b11'
   >>> bin(-10)
   '-0b1010'

   如果不一定需要前缀“0b”，还可以使用如下的方法。

   >>> format(14, '#b'), format(14, 'b')
   ('0b1110', '1110')
   >>> f'{14:#b}', f'{14:b}'
   ('0b1110', '1110')

   另见 "format()" 获取更多信息。

class bool([x])

   返回一个布尔值，"True" 或者 "False"。 *x* 使用标准的 真值测试过程
   来转换。如果 *x* 是假的或者被省略，返回 "False"；其他情况返回
   "True"。"bool" 类是 "int" 的子类（参见 Numeric Types --- int,
   float, complex）。其他类不能继承自它。它只有 "False" 和 "True" 两个
   实例（参见 Boolean Values）。

class bytearray([source[, encoding[, errors]]])

   返回一个新的 bytes 数组。 "bytearray" 类是一个可变序列，包含范围为
   0 <= x < 256 的整数。它有可变序列大部分常见的方法，见 Mutable
   Sequence Types 的描述；同时有 "bytes" 类型的大部分方法，参见 Bytes
   and Bytearray Operations。

   可选形参 *source* 可以用不同的方式来初始化数组：

   * 如果是一个 *string*，您必须提供 *encoding* 参数（*errors* 参数
     仍 是可选的）；"bytearray()" 会使用 "str.encode()" 方法来将
     string 转变成 bytes。

   * 如果是一个 *integer*，会初始化大小为该数字的数组，并使用 null
     字 节填充。

   * 如果是一个符合 *buffer* 接口的对象，该对象的只读 buffer 会用来
     初 始化字节数组。

   * 如果是一个 *iterable* 可迭代对象，它的元素的范围必须是 "0 <= x
     < 256" 的整数，它会被用作数组的初始内容。

   如果没有实参，则创建大小为 0 的数组。

   另见 Binary Sequence Types --- bytes, bytearray, memoryview 和
   Bytearray Objects。

class bytes([source[, encoding[, errors]]])

   返回一个新的“bytes”对象， 是一个不可变序列，包含范围为 "0 <= x <
   256" 的整数。"bytes" 是 "bytearray" 的不可变版本 - 它有其中不改变序
   列的方法和相同的索引、切片操作。

   因此，构造函数的实参和 "bytearray()" 相同。

   字节对象还可以用字面值创建，参见 字符串和字节串字面值。

   另见 Binary Sequence Types --- bytes, bytearray, memoryview，Bytes
   Objects 和 Bytes and Bytearray Operations。

callable(object)

   如果实参 *object* 是可调用的，返回 "True"，否则返回 "False"。如果返
   回真，调用仍可能会失败；但如果返回假，则调用 *object* 肯定会失败。
   注意类是可调用的（调用类会返回一个新的实例）。如果实例的类有
   "__call__()" 方法，则它是可调用。

   3.2 新版功能: 这个函数一开始在 Python 3.0 被移除了，但在 Python 3.2
   被重新加入。

chr(i)

   返回 Unicode 码位为整数 *i* 的字符的字符串格式。例如，"chr(97)" 返
   回字符串 "'a'"，"chr(8364)" 返回字符串 "'€'"。这是 "ord()" 的逆函数
   。

   实参的合法范围是 0 到 1,114,111（16 进制表示是 0x10FFFF）。如果 *i*
   超过这个范围，会触发 "ValueError" 异常。

@classmethod

   把一个方法封装成类方法。

   一个类方法把类自己作为第一个实参，就像一个实例方法把实例自己作为第
   一个实参。请用以下习惯来声明类方法:

      class C:
          @classmethod
          def f(cls, arg1, arg2, ...): ...

   "@classmethod" 形式是一个函数 *装饰器* - 参见 Function definitions
   中关于函数定义的详细介绍。

   它可以同时在类（如 "C.f()"）和实例（如 "C().f()"）上调用。实例除了
   它的类信息，其他都会被忽略。如果一个类方法在子类上调用，子类会作为
   第一个实参传入。

   类方法和 C++ 和 Java 的静态方法是有区别的。如果你想要静态方法，请看
   本节的 "staticmethod()"。

   关于类方法的更多信息，请参考文档 标准类型等级结构 中的标准类型的层
   次。

compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1)

   将 *source* 编译成代码或 AST 对象。代码对象可以被 "exec()" 或
   "eval()" 执行。*source* 可以是常规的字符串、字节字符串，或者 AST 对
   象。参见 "ast" 模块的文档了解如何使用 AST 对象。

   *filename* 实参需要是代码读取的文件名；如果代码不需要从文件中读取，
   可以传入一些可辨识的值（经常会使用 "'<string>'"）。

   *mode* 实参指定了编译代码必须用的模式。如果 *source* 是语句序列，可
   以是 "'exec'"；如果是单一表达式，可以是 "'eval'"；如果是单个交互式
   语句，可以是 "'single'"。（在最后一种情况下，如果表达式执行结果不是
   "None" 将会被打印出来。）

   The optional arguments *flags* and *dont_inherit* control which
   future statements affect the compilation of *source*.  If neither
   is present (or both are zero) the code is compiled with those
   future statements that are in effect in the code that is calling
   "compile()".  If the *flags* argument is given and *dont_inherit*
   is not (or is zero) then the future statements specified by the
   *flags* argument are used in addition to those that would be used
   anyway. If *dont_inherit* is a non-zero integer then the *flags*
   argument is it -- the future statements in effect around the call
   to compile are ignored.

   Future 语句使用比特位来指定，多个语句可以通过按位或来指定。具体特性
   的比特位可以通过 "__future__"  模块中的 "_Feature" 类的实例的
   "compiler_flag" 属性来获得。

   *optimize* 实参指定编译器的优化级别；默认值 "-1"  选择与解释器的
   "-O" 选项相同的优化级别。显式级别为 "0" （没有优化；"__debug__"  为
   真）、"1" （断言被删除， "__debug__" 为假）或 "2" （文档字符串也被
   删除）。

   如果编译的源码不合法，此函数会触发 "SyntaxError" 异常；如果源码包含
   null 字节，则会触发 "ValueError" 异常。

   如果您想分析 Python 代码的 AST 表示，请参阅 "ast.parse()"。

   注解: 在 "'single'"  或 "'eval'" 模式编译多行代码字符串时，输入必
     须以至 少一个换行符结尾。 这使 "code" 模块更容易检测语句的完整性
     。

   警告: 如果编译足够大或者足够复杂的字符串成 AST 对象时，Python 解
     释器会 因为 Python AST 编译器的栈深度限制而奔溃。

   在 3.2 版更改: 允许使用 Windows 和 Mac 的换行符。在 "'exec'" 模式不
   再需要以换行符结尾。增加了  *optimize* 形参。

   在 3.5 版更改: 之前 *source* 中包含 null 字节的话会触发 "TypeError"
   异常。

class complex([real[, imag]])

   返回值为 *real* + *imag**1j 的复数，或将字符串或数字转换为复数。如
   果第一个形参是字符串，则它被解释为一个复数，并且函数调用时必须没有
   第二个形参。第二个形参不能是字符串。每个实参都可以是任意的数值类型
   （包括复数）。如果省略了 *imag*，则默认值为零，构造函数会像 "int"
   和 "float" 一样进行数值转换。如果两个实参都省略，则返回 "0j"。

   注解: 当从字符串转换时，字符串在 "+" 或 "-" 的周围必须不能有空格
     。例如 "complex('1+2j')" 是合法的，但 "complex('1 + 2j')" 会触发
     "ValueError" 异常。

   Numeric Types --- int, float, complex 描述了复数类型。

   在 3.6 版更改: 您可以使用下划线将代码文字中的数字进行分组。

delattr(object, name)

   "setattr()" 相关的函数。实参是一个对象和一个字符串。该字符串必须是
   对象的某个属性。如果对象允许，该函数将删除指定的属性。例如
   "delattr(x, 'foobar')"  等价于 "del x.foobar" 。

class dict(**kwarg)
class dict(mapping, **kwarg)
class dict(iterable, **kwarg)

   创建一个新的字典。"dict" 对象是一个字典类。参见 "dict" 和 Mapping
   Types --- dict 了解这个类。

   其他容器类型，请参见内置的 "list"、"set" 和 "tuple" 类，以及
   "collections" 模块。

dir([object])

   如果没有实参，则返回当前本地作用域中的名称列表。如果有实参，它会尝
   试返回该对象的有效属性列表。

   如果对象有一个名为 "__dir__()" 的方法，那么该方法将被调用，并且必须
   返回一个属性列表。这允许实现自定义 "__getattr__()" 或
   "__getattribute__()" 函数的对象能够自定义 "dir()" 来报告它们的属性
   。

   如果对象不提供 "__dir__()"，这个函数会尝试从对象已定义的 "__dict__"
   属性和类型对象收集信息。结果列表并不总是完整的，如果对象有自定义
   "__getattr__()"，那结果可能不准确。

   默认的 "dir()" 机制对不同类型的对象行为不同，它会试图返回最相关而不
   是最全的信息：

   * 如果对象是模块对象，则列表包含模块的属性名称。

   * 如果对象是类型或类对象，则列表包含它们的属性名称，并且递归查找
     所 有基类的属性。

   * 否则，列表包含对象的属性名称，它的类属性名称，并且递归查找它的
     类 的所有基类的属性。

   返回的列表按字母表排序。例如：

   >>> import struct
   >>> dir()   # show the names in the module namespace
   ['__builtins__', '__name__', 'struct']
   >>> dir(struct)   # show the names in the struct module # doctest: +SKIP
   ['Struct', '__all__', '__builtins__', '__cached__', '__doc__', '__file__',
    '__initializing__', '__loader__', '__name__', '__package__',
    '_clearcache', 'calcsize', 'error', 'pack', 'pack_into',
    'unpack', 'unpack_from']
   >>> class Shape:
   ...     def __dir__(self):
   ...         return ['area', 'perimeter', 'location']
   >>> s = Shape()
   >>> dir(s)
   ['area', 'location', 'perimeter']

   注解: 因为 "dir()" 主要是为了便于在交互式时使用，所以它会试图返回
     人们感 兴趣的名字集合，而不是试图保证结果的严格性或一致性，它具体
     的行为 也可能在不同版本之间改变。例如，当实参是一个类时，
     metaclass 的属 性不包含在结果列表中。

divmod(a, b)

   它将两个（非复数）数字作为实参，并在执行整数除法时返回一对商和余数
   。对于混合操作数类型，适用双目算术运算符的规则。对于整数，结果和
   "(a // b, a % b)" 一致。对于浮点数，结果是 "(q, a % b)" ，*q* 通常
   是 "math.floor(a / b)" 但可能会比 1 小。在任何情况下， "q * b + a %
   b" 和  *a* 基本相等；如果 "a % b" 非零，它的符号和 *b* 一样，并且
   "0 <= abs(a % b) < abs(b)" 。

enumerate(iterable, start=0)

   返回一个枚举对象。*iterable* 必须是一个序列，或 *迭代器*，或其他支
   持迭代的对象。 "enumerate()" 返回的迭代器的 "__next__()" 方法返回一
   个元组，里面包含一个计数值（从 *start* 开始，默认为 0）和通过迭代
   *iterable* 获得的值。

   >>> seasons = ['Spring', 'Summer', 'Fall', 'Winter']
   >>> list(enumerate(seasons))
   [(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
   >>> list(enumerate(seasons, start=1))
   [(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]

   等价于:

      def enumerate(sequence, start=0):
          n = start
          for elem in sequence:
              yield n, elem
              n += 1

eval(expression, globals=None, locals=None)

   实参是一个字符串，以及可选的 globals 和 locals。*globals* 实参必须
   是一个字典。*locals* 可以是任何映射对象。

   The *expression* argument is parsed and evaluated as a Python
   expression (technically speaking, a condition list) using the
   *globals* and *locals* dictionaries as global and local namespace.
   If the *globals* dictionary is present and does not contain a value
   for the key "__builtins__", a reference to the dictionary of the
   built-in module "builtins" is inserted under that key before
   *expression* is parsed. This means that *expression* normally has
   full access to the standard "builtins" module and restricted
   environments are propagated.  If the *locals* dictionary is omitted
   it defaults to the *globals* dictionary.  If both dictionaries are
   omitted, the expression is executed in the environment where
   "eval()" is called.  The return value is the result of the
   evaluated expression. Syntax errors are reported as exceptions.
   Example:

   >>> x = 1
   >>> eval('x+1')
   2

   这个函数也可以用来执行任何代码对象（如 "compile()"  创建的）。这种
   情况下，参数是代码对象，而不是字符串。如果编译该对象时的 *mode* 实
   参是 "'exec'" 那么 "eval()" 返回值为 "None" 。

   提示： "exec()" 函数支持动态执行语句。 "globals()" 和 "locals()" 函
   数各自返回当前的全局和本地字典，因此您可以将它们传递给 "eval()" 或
   "exec()" 来使用。

   另外可以参阅 "ast.literal_eval()"，该函数可以安全执行仅包含文字的表
   达式字符串。

exec(object[, globals[, locals]])

   这个函数支持动态执行 Python 代码。*object* 必须是字符串或者代码对象
   。如果是字符串，那么该字符串将被解析为一系列 Python 语句并执行（除
   非发生语法错误）。[1] 如果是代码对象，它将被直接执行。在任何情况下
   ，被执行的代码都需要和文件输入一样是有效的（见参考手册中关于文件输
   入的章节）。请注意即使在传递给 "exec()" 函数的代码的上下文中，
   "return" 和 "yield" 语句也不能在函数定义之外使用。该函数返回值是
   "None" 。

   无论哪种情况，如果省略了可选参数，代码将在当前范围内执行。如果提供
   了 *globals* 参数，就必须是字典类型，而且会被用作全局和本地变量。如
   果同时提供了 *globals* 和 *locals* 参数，它们分别被用作全局和本地变
   量。如果提供了 *locals* 参数，则它可以是任何映射型的对象。请记住在
   模块层级，全局和本地变量是相同的字典。如果 exec 有两个不同的
   *globals* 和 *locals* 对象，代码就像嵌入在类定义中一样执行。

   如果 *globals* 字典不包含 "__builtins__" 键值，则将为该键插入对内建
   "builtins" 模块字典的引用。因此，在将执行的代码传递给 "exec()" 之前
   ，可以通过将自己的 "__builtins__" 字典插入到 *globals* 中来控制可以
   使用哪些内置代码。

   注解: 内置 "globals()" 和 "locals()" 函数各自返回当前的全局和本地
     字典， 因此可以将它们传递给 "exec()" 的第二个和第三个实参。

   注解: 默认情况下，*locals* 的行为如下面 "locals()" 函数描述的一样
     ：不要 试图改变默认的 *locals* 字典。如果您想在 "exec()" 函数返回
     时知道 代码对 *locals* 的变动，请明确地传递 *locals* 字典。

filter(function, iterable)

   用 *iterable*  中函数 *function* 返回真的那些元素，构建一个新的迭代
   器。*iterable* 可以是一个序列，一个支持迭代的容器，或一个迭代器。如
   果 *function* 是 "None" ，则会假设它是一个身份函数，即 *iterable*
   中所有返回假的元素会被移除。

   请注意， "filter(function, iterable)" 相当于一个生成器表达式，当
   function 不是 "None" 的时候为 "(item for item in iterable if
   function(item))"；function 是 "None" 的时候为 "(item for item in
   iterable if item)" 。

   请参阅 "itertools.filterfalse()" 了解，只有 *function* 返回 false
   时才选取 *iterable* 中元素的补充函数。

class float([x])

   返回从数字或字符串 *x* 生成的浮点数。

   如果实参是字符串，则它必须是包含十进制数字的字符串，字符串前面可以
   有符号，之前也可以有空格。可选的符号有 "'+'" 和 "'-'" ； "'+'" 对创
   建的值没有影响。实参也可以是 NaN（非数字）、正负无穷大的字符串。确
   切地说，除去首尾的空格后，输入必须遵循以下语法：

      sign           ::= "+" | "-"
      infinity       ::= "Infinity" | "inf"
      nan            ::= "nan"
      numeric_value  ::= floatnumber | infinity | nan
      numeric_string ::= [sign] numeric_value

   这里， "floatnumber" 是 Python 浮点数的字符串形式，详见 浮点数字面
   值。字母大小写都可以，例如，“inf”、“Inf”、“INFINITY”、“iNfINity” 都
   可以表示正无穷大。

   另一方面，如果实参是整数或浮点数，则返回具有相同值（在 Python 浮点
   精度范围内）的浮点数。如果实参在 Python 浮点精度范围外，则会触发
   "OverflowError"。

   对于一般的 Python 对象 "x" ， "float(x)" 指派给 "x.__float__()" 。

   如果没有实参，则返回 "0.0" 。

   例如:

      >>> float('+1.23')
      1.23
      >>> float('   -12345\n')
      -12345.0
      >>> float('1e-003')
      0.001
      >>> float('+1E6')
      1000000.0
      >>> float('-Infinity')
      -inf

   Numeric Types --- int, float, complex 描述了浮点类型。

   在 3.6 版更改: 您可以使用下划线将代码文字中的数字进行分组。

format(value[, format_spec])

   将 *value* 转换为 *format_spec* 控制的“格式化”表示。*format_spec*
   的解释取决于 *value* 实参的类型，但是大多数内置类型使用标准格式化语
   法：Format Specification Mini-Language。

   默认的 *format_spec* 是一个空字符串，它通常和调用 "str(value)" 的结
   果相同。

   调用 "format(value, format_spec)" 会转换成
   "type(value).__format__(value, format_spec)" ，所以实例字典中的
   "__format__()" 方法将不会调用。如果搜索到 "object" 有这个方法但
   *format_spec* 不为空，*format_spec* 或返回值不是字符串，会触发
   "TypeError" 异常。

   在 3.4 版更改: 当 *format_spec* 不是空字符串时，
   "object().__format__(format_spec)" 会触发  "TypeError"。

class frozenset([iterable])

   返回一个新的 "frozenset" 对象，它包含可选参数 *iterable* 中的元素。
   "frozenset" 是一个内置的类。有关此类的文档，请参阅 "frozenset" 和
   Set Types --- set, frozenset。

   请参阅内建的 "set"、"list"、"tuple" 和 "dict" 类，以及
   "collections" 模块来了解其它的容器。

getattr(object, name[, default])

   返回对象命名属性的值。*name* 必须是字符串。如果该字符串是对象的属性
   之一，则返回该属性的值。例如， "getattr(x, 'foobar')" 等同于
   "x.foobar"。如果指定的属性不存在，且提供了 *default* 值，则返回它，
   否则触发 "AttributeError"。

globals()

   返回表示当前全局符号表的字典。这总是当前模块的字典（在函数或方法中
   ，不是调用它的模块，而是定义它的模块）。

hasattr(object, name)

   该实参是一个对象和一个字符串。如果字符串是对象的属性之一的名称，则
   返回 "True"，否则返回 "False"。（此功能是通过调用 "getattr(object,
   name)" 看是否有 "AttributeError" 异常来实现的。）

hash(object)

   返回该对象的哈希值（如果它有的话）。哈希值是整数。它们在字典查找元
   素时用来快速比较字典的键。相同大小的数字变量有相同的哈希值（即使它
   们类型不同，如 1 和 1.0）。

   注解: 如果对象实现了自己的 "__hash__()" 方法，请注意，"hash()" 根
     据机器 的字长来截断返回值。另请参阅 "__hash__()"。

help([object])

   启动内置的帮助系统（此函数主要在交互式中使用）。如果没有实参，解释
   器控制台里会启动交互式帮助系统。如果实参是一个字符串，则在模块、函
   数、类、方法、关键字或文档主题中搜索该字符串，并在控制台上打印帮助
   信息。如果实参是其他任意对象，则会生成该对象的帮助页。

   该函数通过 "site" 模块加入到内置命名空间。

   在 3.4 版更改: "pydoc" 和 "inspect" 的变更使得可调用对象的签名信息
   更加全面和一致。

hex(x)

   将整数转换为以“0x”为前缀的小写十六进制字符串。如果 *x* 不是 Python
   "int" 对象，则必须定义返回整数的 "__index__()" 方法。一些例子：

   >>> hex(255)
   '0xff'
   >>> hex(-42)
   '-0x2a'

   如果要将整数转换为大写或小写的十六进制字符串，并可选择有无“0x”前缀
   ，则可以使用如下方法：

   >>> '%#x' % 255, '%x' % 255, '%X' % 255
   ('0xff', 'ff', 'FF')
   >>> format(255, '#x'), format(255, 'x'), format(255, 'X')
   ('0xff', 'ff', 'FF')
   >>> f'{255:#x}', f'{255:x}', f'{255:X}'
   ('0xff', 'ff', 'FF')

   另见 "format()" 获取更多信息。

   另请参阅 "int()" 将十六进制字符串转换为以 16 为基数的整数。

   注解: 如果要获取浮点数的十六进制字符串形式，请使用 "float.hex()"
     方法。

id(object)

   返回对象的“标识值”。该值是一个整数，在此对象的生命周期中保证是唯一
   且恒定的。两个生命期不重叠的对象可能具有相同的 "id()" 值。

   **CPython implementation detail:** This is the address of the
   object in memory.

input([prompt])

   如果存在 *prompt* 实参，则将其写入标准输出，末尾不带换行符。接下来
   ，该函数从输入中读取一行，将其转换为字符串（除了末尾的换行符）并返
   回。当读取到 EOF 时，则触发 "EOFError"。例如:

      >>> s = input('--> ')  
      --> Monty Python's Flying Circus
      >>> s  
      "Monty Python's Flying Circus"

   如果加载了 "readline" 模块，"input()" 将使用它来提供复杂的行编辑和
   历史记录功能。

class int(x=0)
class int(x, base=10)

   返回一个使用数字或字符串 *x* 生成的整数对象，或者没有实参的时候返回
   "0" 。如果 *x* 定义了 "__int__()"，"int(x)" 返回 "x.__int__()" 。如
   果 *x* 定义了 "__trunc__()"，它返回 "x.__trunc__()" 。对于浮点数，
   它向零舍入。

   如果 *x* 不是数字，或者有 *base* 参数，*x* 必须是字符串、"bytes"、
   表示进制为 *base* 的 整数文字 的 "bytearray" 实例。该文字前可以有
   "+" 或 "-" （中间不能有空格），前后可以有空格。一个进制为 n 的数字
   包含 0 到 n-1 的数，其中 "a" 到 "z" （或 "A" 到 "Z" ）表示 10 到 35
   。默认的 *base* 为 10 ，允许的进制有 0、2-36。2、8、16 进制的数字可
   以在代码中用 "0b"/"0B" 、 "0o"/"0O" 、 "0x"/"0X" 前缀来表示。进制为
   0 将安照代码的字面量来精确解释，最后的结果会是 2、8、10、16 进制中
   的一个。所以 "int('010', 0)" 是非法的，但 "int('010')" 和
   "int('010', 8)" 是合法的。

   整数类型定义请参阅 Numeric Types --- int, float, complex 。

   在 3.4 版更改: 如果 *base* 不是 "int" 的实例，但 *base* 对象有
   "base.__index__" 方法，则会调用该方法来获取进制数。以前的版本使用
   "base.__int__" 而不是 "base.__index__"。

   在 3.6 版更改: 您可以使用下划线将代码文字中的数字进行分组。

isinstance(object, classinfo)

   如果 *object* 实参是 *classinfo* 实参的实例，或者是（直接、间接或 *
   虚拟*）子类的实例，则返回 true。如果 *object* 不是给定类型的对象，
   函数始终返回 false。如果 *classinfo* 是对象类型（或多个递归元组）的
   元组，如果 *object* 是其中的任何一个的实例则返回 true。 如果
   *classinfo* 既不是类型，也不是类型元组或类型的递归元组，那么会触发
   "TypeError" 异常。

issubclass(class, classinfo)

   如果 *class* 是 *classinfo* 的子类（直接、间接或 *虚拟* 的），则返
   回 true。*classinfo* 可以是类对象的元组，此时 *classinfo* 中的每个
   元素都会被检查。其他情况，会触发 "TypeError" 异常。

iter(object[, sentinel])

   返回一个 *迭代器* 对象。根据是否存在第二个实参，第一个实参的解释是
   非常不同的。如果没有第二个实参，*object* 必须是支持迭代协议（有
   "__iter__()" 方法）的集合对象，或必须支持序列协议（有
   "__getitem__()" 方法，且数字参数从 "0" 开始）。如果它不支持这些协议
   ，会触发 "TypeError"。如果有第二个实参 *sentinel*，那么 *object* 必
   须是可调用的对象。这种情况下生成的迭代器，每次迭代调用它的
   "__next__()" 方法时都会不带实参地调用 *object*；如果返回的结果是
   *sentinel* 则触发 "StopIteration"，否则返回调用结果。

   另请参阅 Iterator Types。

   "iter()" 的第二种形式的一个有用的用法是将文件读到特定行。在下面的例
   子中，我们将读取文件，直到 "readline()" 方法返回一个空字符串

      with open('mydata.txt') as fp:
          for line in iter(fp.readline, ''):
              process_line(line)

len(s)

   返回对象的长度（元素个数）。实参可以是序列（如 string、bytes、tuple
   、list 或 range 等）或集合（如 dictionary、set 或 frozen set 等）。

class list([iterable])

   除了是函数，"list" 也是可变序列类型，详情请参阅 列表 和 Sequence
   Types --- list, tuple, range。

locals()

   更新并返回表示当前本地符号表的字典。在函数块而不是类块中调用
   "locals()" 时会返回自由变量。

   注解: 不要更改此字典的内容；更改不会影响解释器使用的局部变量或自
     由变量 的值。

map(function, iterable, ...)

   产生一个将 *function* 应用于迭代器中所有元素并返回结果的迭代器。如
   果传递了额外的 *iterable* 实参，*function* 必须接受相同个数的实参，
   并使用所有迭代器中并行获取的元素。当有多个迭代器时，最短的迭代器耗
   尽则整个迭代结束。如果函数的输入已经是元组实参，请参阅
   "itertools.starmap()"。

max(iterable, *[, key, default])
max(arg1, arg2, *args[, key])

   返回可迭代对象中最大的元素，或者返回两个及以上实参中最大的。

   如果只提供了一个 positional 实参，它必须是非空 *可迭代对象*，返回可
   迭代对象中最大的元素；如果提供了两个及以上的 positional 实参，则返
   回最大的 positional 实参。

   有两个可选只能用关键字的实参。*key* 实参指定排序函数用的参数，如传
   给 "list.sort()" 的。*default* 实参是当可迭代对象为空时返回的值。如
   果可迭代对象为空，并且没有给 *default* ，则会触发 "ValueError"。

   如果有多个最大元素，则此函数将返回第一个找到的。这和其他稳定排序工
   具如 "sorted(iterable, key=keyfunc, reverse=True)[0]" 和
   "heapq.nlargest(1, iterable, key=keyfunc)" 保持一致。

   3.4 新版功能: keyword-only 实参 *default* 。

memoryview(obj)

   返回由给定实参创建的“内存视图”对象。有关详细信息，请参阅 Memory
   Views。

min(iterable, *[, key, default])
min(arg1, arg2, *args[, key])

   返回可迭代对象中最小的元素，或者返回两个及以上实参中最小的。

   如果只提供了一个 positional 实参，它必须是 *可迭代对象*，返回可迭代
   对象中最小的元素；如果提供了两个及以上的 positional 实参，则返回最
   小的 positional 实参。

   有两个可选只能用关键字的实参。*key* 实参指定排序函数用的参数，如传
   给 "list.sort()" 的。*default* 实参是当可迭代对象为空时返回的值。如
   果可迭代对象为空，并且没有给 *default* ，则会触发 "ValueError"。

   如果有多个最小元素，则此函数将返回第一个找到的。这和其他稳定排序工
   具如 "sorted(iterable, key=keyfunc)[0]" 和 "heapq.nsmallest(1,
   iterable, key=keyfunc)" 保持一致。

   3.4 新版功能: keyword-only 实参 *default* 。

next(iterator[, default])

   通过调用 *iterator* 的 "__next__()" 方法获取下一个元素。如果迭代器
   耗尽，则返回给定的 *default*，如果没有默认值则触发 "StopIteration"
   。

class object

   返回一个没有特征的新对象。"object" 是所有类的基类。它具有所有
   Python 类实例的通用方法。这个函数不接受任何实参。

   注解: 由于 "object" 没有 "__dict__"，因此无法将任意属性赋给
     "object" 的 实例。

oct(x)

   将一个整数转变为一个前缀为“0o”的八进制字符串。结果是一个合法的
   Python 表达式。如果 *x* 不是 Python 的 "int" 对象，那它需要定义
   "__index__()"  方法返回一个整数。一些例子：

   >>> oct(8)
   '0o10'
   >>> oct(-56)
   '-0o70'

   如果要将整数转换为八进制字符串，并可选择有无“0o”前缀，则可以使用如
   下方法：

   >>> '%#o' % 10, '%o' % 10
   ('0o12', '12')
   >>> format(10, '#o'), format(10, 'o')
   ('0o12', '12')
   >>> f'{10:#o}', f'{10:o}'
   ('0o12', '12')

   另见 "format()" 获取更多信息。

open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)

   打开 *file* 并返回对应的 *文件对象*。如果该文件不能打开，则触发
   "OSError"。

   *file* 是将要打开的文件的路径（绝对路径或者当前工作目录的相当路径）
   ，是一个 *path-like 对象*；也可能是要被封装的文件描述符的数字。（如
   果是文件描述符，它会随着返回的 I/O 对象关闭而关闭，除非 *closefd*
   是 "False" 。）

   *mode* 是一个可选字符串，用于指定打开文件的模式。默认值是 "'r'"  ，
   这意味着它以文本模式打开并读取。其他常见模式有：写入 "'w'" （截断已
   经存在的文件）；排它性创建 "'x'" ；追加写 "'a'" （在 *一些*  Unix
   系统上，无论当前的文件指针在什么位置，*所有* 写入都会追加到文件末尾
   ）。在文本模式，如果 *encoding* 没有指定，则根据平台来决定使用的编
   码：使用 "locale.getpreferredencoding(False)" 来获取本地编码。（要
   读取和写入原始字节，请使用二进制模式并不要指定 *encoding*。）可用的
   模式有：

   +-----------+-----------------------------------------------------------------+
   | 字符      | 意义                                                            |
   +===========+=================================================================+
   | "'r'"     | 读取（默认）                                                    |
   +-----------+-----------------------------------------------------------------+
   | "'w'"     | 写入，并先截断文件                                              |
   +-----------+-----------------------------------------------------------------+
   | "'x'"     | 排它性创建，如果文件已存在则失败                                |
   +-----------+-----------------------------------------------------------------+
   | "'a'"     | 写入，如果文件存在则在末尾追加                                  |
   +-----------+-----------------------------------------------------------------+
   | "'b'"     | 二进制模式                                                      |
   +-----------+-----------------------------------------------------------------+
   | "'t'"     | 文本模式（默认）                                                |
   +-----------+-----------------------------------------------------------------+
   | "'+'"     | 更新磁盘文件（读取并写入）                                      |
   +-----------+-----------------------------------------------------------------+
   | "'U'"     | *通用换行* 模式（已弃用）                                       |
   +-----------+-----------------------------------------------------------------+

   默认的模式是 "'r'" （打开并读取文本，同 "'rt'" ）。对于二进制写入，
   "'w+b'" 模式打开并把文件截断成 0 字节； "'r+b'" 则不会截断。

   正如在 Overview 中提到的，Python区分二进制和文本I/O。以二进制模式打
   开的文件（包括 *mode* 参数中的 "'b'" ）返回的内容为 "bytes`对象，不
   进行任何解码。在文本模式下（默认情况下，或者在 *mode* 参数中包含
   `"'t'` ）时，文件内容返回为 "str" ，首先使用指定的 *encoding* （如
   果给定）或者使用平台默认的的字节编码解码。

   注解: Python不依赖于底层操作系统的文本文件概念;所有处理都由Python
     本身完 成，因此与平台无关。

   *buffering* 是一个可选的整数，用于设置缓冲策略。传递0以切换缓冲关闭
   （仅允许在二进制模式下），1选择行缓冲（仅在文本模式下可用），并且>1
   的整数以指示固定大小的块缓冲区的大小（以字节为单位）。如果没有给出
   *buffering* 参数，则默认缓冲策略的工作方式如下:

   * 二进制文件以固定大小的块进行缓冲；使用启发式方法选择缓冲区的大
     小 ，尝试确定底层设备的“块大小”或使用 "io.DEFAULT_BUFFER_SIZE"。
     在许 多系统上，缓冲区的长度通常为4096或8192字节。

   * “交互式”文本文件（ "isatty()" 返回 "True" 的文件）使用行缓冲。
     其 他文本文件使用上述策略用于二进制文件。

   *encoding* 是用于解码或编码文件的编码的名称。这应该只在文本模式下使
   用。默认编码是依赖于平台的（不 管 "locale.getpreferredencoding()"
   返回何值），但可以使用任何Python支持的 *text encoding* 。有关支持的
   编码列表，请参阅 "codecs" 模块。

   *errors* 是一个可选的字符串参数，用于指定如何处理编码和解码错误 -
   这不能在二进制模式下使用。可以使用各种标准错误处理程序（列在 Error
   Handlers ），但是使用 "codecs.register_error()" 注册的任何错误处理
   名称也是有效的。标准名称包括:

   * 如果存在编码错误，"'strict'" 会引发 "ValueError" 异常。 默认值
     "None" 具有相同的效果。

   * "'ignore'" 忽略错误。请注意，忽略编码错误可能会导致数据丢失。

   * "'replace'" 会将替换标记（例如 "'?'" ）插入有错误数据的地方。

   * "'surrogateescape'" 将表示任何不正确的字节作为Unicode专用区中的
     代 码点，范围从U+DC80到U+DCFF。当在写入数据时使用
     "surrogateescape" 错误处理程序时，这些私有代码点将被转回到相同的
     字节中。这对于处理 未知编码的文件很有用。

   * 只有在写入文件时才支持 "'xmlcharrefreplace'"。编码不支持的字符
     将 替换为相应的XML字符引用 "&#nnn;"。

   * "'backslashreplace'" 用Python的反向转义序列替换格式错误的数据。

   * "'namereplace'" （也只在编写时支持）用 "\N{...}" 转义序列替换不
     支 持的字符。

   *newline* 控制 *universal newlines* 模式如何生效（它仅适用于文本模
   式）。它可以是 "None"，"''"，"'\n'"，"'\r'" 和 "'\r\n'"。它的工作原
   理:

   * 从流中读取输入时，如果 *newline* 为 "None"，则启用通用换行模式
     。 输入中的行可以以 "'\n'"，"'\r'" 或 "'\r\n'" 结尾，这些行被翻译
     成 "'\n'" 在返回呼叫者之前。如果它是 "''"，则启用通用换行模式，但
     行 结尾将返回给调用者未翻译。如果它具有任何其他合法值，则输入行仅
     由 给定字符串终止，并且行结尾将返回给未调用的调用者。

   * 将输出写入流时，如果 *newline* 为 "None"，则写入的任何 "'\n'"
     字 符都将转换为系统默认行分隔符 "os.linesep"。如果 *newline* 是
     "''" 或 "'\n'"，则不进行翻译。如果 *newline* 是任何其他合法值，则
     写入 的任何 "'\n'" 字符将被转换为给定的字符串。

   如果 *closefd* 是 "False" 并且给出了文件描述符而不是文件名，那么当
   文件关闭时，底层文件描述符将保持打开状态。如果给出文件名则
   *closefd* 必须为 "True" （默认值），否则将引发错误。

   可以通过传递可调用的 *opener* 来使用自定义开启器。然后通过使用参数
   （ *file*，*flags* ）调用 *opener* 获得文件对象的基础文件描述符。
   *opener* 必须返回一个打开的文件描述符（使用 "os.open" as *opener*
   时与传递 "None" 的效果相同）。

   新创建的文件是 不可继承的。

   下面的示例使用 "os.open()" 函数返回值传给 dir_fd 的形参，从给定的目
   录中用相对路径打开文件:

      >>> import os
      >>> dir_fd = os.open('somedir', os.O_RDONLY)
      >>> def opener(path, flags):
      ...     return os.open(path, flags, dir_fd=dir_fd)
      ...
      >>> with open('spamspam.txt', 'w', opener=opener) as f:
      ...     print('This will be written to somedir/spamspam.txt', file=f)
      ...
      >>> os.close(dir_fd)  # don't leak a file descriptor

   The type of *file object* returned by the "open()" function depends
   on the mode.  When "open()" is used to open a file in a text mode
   ("'w'", "'r'", "'wt'", "'rt'", etc.), it returns a subclass of
   "io.TextIOBase" (specifically "io.TextIOWrapper").  When used to
   open a file in a binary mode with buffering, the returned class is
   a subclass of "io.BufferedIOBase".  The exact class varies: in read
   binary mode, it returns an "io.BufferedReader"; in write binary and
   append binary modes, it returns an "io.BufferedWriter", and in
   read/write mode, it returns an "io.BufferedRandom".  When buffering
   is disabled, the raw stream, a subclass of "io.RawIOBase",
   "io.FileIO", is returned.

   另请参阅文件操作模块，例如 "fileinput"、"io" （声明了 "open()"）、
   "os"、"os.path"、"tempfile" 和 "shutil"。

      在 3.3 版更改:

      * 增加了 *opener* 形参。

      * 增加了 "'x'" 模式。

      * 过去触发的 "IOError"，现在是 "OSError" 的别名。

      * 如果文件已存在但使用了排它性创建模式（ "'x'" ），现在会触发
        "FileExistsError"。

      在 3.4 版更改:

      * 文件现在禁止继承。

   Deprecated since version 3.4, will be removed in version 4.0: "'U'"
   模式。

      在 3.5 版更改:

      * 如果系统调用被中断，但信号处理程序没有触发异常，此函数现在会
        重 试系统调用，而不是触发 "InterruptedError" 异常（原因详见
        **PEP 475**）。

      * 增加了 "'namereplace'" 错误处理接口。

      在 3.6 版更改:

      * 增加对实现了 "os.PathLike" 对象的支持。

      * 在 Windows 上，打开一个控制台缓冲区将返回 "io.RawIOBase" 的
        子 类，而不是 "io.FileIO"。

ord(c)

   对表示单个 Unicode 字符的字符串，返回代表它 Unicode 码点的整数。例
   如 "ord('a')" 返回整数 "97"， "ord('€')" （欧元符合）返回 "8364" 。
   这是 "chr()" 的逆函数。

pow(x, y[, z])

   返回 *x* 的 *y* 次幂；如果 *z* 存在，则对 *z* 取余（比直接 "pow(x,
   y) % z" 计算更高效）。两个参数形式的 "pow(x, y)" 等价于幂运算符：
   "x**y"。

   The arguments must have numeric types.  With mixed operand types,
   the coercion rules for binary arithmetic operators apply.  For
   "int" operands, the result has the same type as the operands (after
   coercion) unless the second argument is negative; in that case, all
   arguments are converted to float and a float result is delivered.
   For example, "10**2" returns "100", but "10**-2" returns "0.01".
   If the second argument is negative, the third argument must be
   omitted.  If *z* is present, *x* and *y* must be of integer types,
   and *y* must be non-negative.

print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)

   Print *objects* to the text stream *file*, separated by *sep* and
   followed by *end*.  *sep*, *end*, *file* and *flush*, if present,
   must be given as keyword arguments.

   All non-keyword arguments are converted to strings like "str()"
   does and written to the stream, separated by *sep* and followed by
   *end*.  Both *sep* and *end* must be strings; they can also be
   "None", which means to use the default values.  If no *objects* are
   given, "print()" will just write *end*.

   The *file* argument must be an object with a "write(string)"
   method; if it is not present or "None", "sys.stdout" will be used.
   Since printed arguments are converted to text strings, "print()"
   cannot be used with binary mode file objects.  For these, use
   "file.write(...)" instead.

   Whether output is buffered is usually determined by *file*, but if
   the *flush* keyword argument is true, the stream is forcibly
   flushed.

   在 3.3 版更改: 增加了 *flush* keyword 实参。

class property(fget=None, fset=None, fdel=None, doc=None)

   返回 property 属性。

   *fget* 是获取属性值的函数。 *fset* 是用于设置属性值的函数。 *fdel*
   是用于删除属性值的函数。并且 *doc* 为属性对象创建文档字符串。

   一个典型的用法是定义一个托管属性 "x":

      class C:
          def __init__(self):
              self._x = None

          def getx(self):
              return self._x

          def setx(self, value):
              self._x = value

          def delx(self):
              del self._x

          x = property(getx, setx, delx, "I'm the 'x' property.")

   如果 *c* 是 *C* 的实例，"c.x" 将调用getter，"c.x = value" 将调用
   setter， "del c.x" 将调用deleter。

   If given, *doc* will be the docstring of the property attribute.
   Otherwise, the property will copy *fget*'s docstring (if it
   exists).  This makes it possible to create read-only properties
   easily using "property()" as a *decorator*:

      class Parrot:
          def __init__(self):
              self._voltage = 100000

          @property
          def voltage(self):
              """Get the current voltage."""
              return self._voltage

   The "@property" decorator turns the "voltage()" method into a
   "getter" for a read-only attribute with the same name, and it sets
   the docstring for *voltage* to "Get the current voltage."

   A property object has "getter", "setter", and "deleter" methods
   usable as decorators that create a copy of the property with the
   corresponding accessor function set to the decorated function.
   This is best explained with an example:

      class C:
          def __init__(self):
              self._x = None

          @property
          def x(self):
              """I'm the 'x' property."""
              return self._x

          @x.setter
          def x(self, value):
              self._x = value

          @x.deleter
          def x(self):
              del self._x

   This code is exactly equivalent to the first example.  Be sure to
   give the additional functions the same name as the original
   property ("x" in this case.)

   The returned property object also has the attributes "fget",
   "fset", and "fdel" corresponding to the constructor arguments.

   在 3.5 版更改: The docstrings of property objects are now
   writeable.

range(stop)
range(start, stop[, step])

   Rather than being a function, "range" is actually an immutable
   sequence type, as documented in Ranges and Sequence Types --- list,
   tuple, range.

repr(object)

   Return a string containing a printable representation of an object.
   For many types, this function makes an attempt to return a string
   that would yield an object with the same value when passed to
   "eval()", otherwise the representation is a string enclosed in
   angle brackets that contains the name of the type of the object
   together with additional information often including the name and
   address of the object.  A class can control what this function
   returns for its instances by defining a "__repr__()" method.

reversed(seq)

   Return a reverse *iterator*.  *seq* must be an object which has a
   "__reversed__()" method or supports the sequence protocol (the
   "__len__()" method and the "__getitem__()" method with integer
   arguments starting at "0").

round(number[, ndigits])

   Return *number* rounded to *ndigits* precision after the decimal
   point.  If *ndigits* is omitted or is "None", it returns the
   nearest integer to its input.

   For the built-in types supporting "round()", values are rounded to
   the closest multiple of 10 to the power minus *ndigits*; if two
   multiples are equally close, rounding is done toward the even
   choice (so, for example, both "round(0.5)" and "round(-0.5)" are
   "0", and "round(1.5)" is "2").  Any integer value is valid for
   *ndigits* (positive, zero, or negative).  The return value is an
   integer if *ndigits* is omitted or "None". Otherwise the return
   value has the same type as *number*.

   For a general Python object "number", "round" delegates to
   "number.__round__".

   注解: The behavior of "round()" for floats can be surprising: for
     example, "round(2.675, 2)" gives "2.67" instead of the expected
     "2.68". This is not a bug: it's a result of the fact that most
     decimal fractions can't be represented exactly as a float.  See
     浮点算术：争议和限制 for more information.

class set([iterable])

   Return a new "set" object, optionally with elements taken from
   *iterable*.  "set" is a built-in class.  See "set" and Set Types
   --- set, frozenset for documentation about this class.

   For other containers see the built-in "frozenset", "list", "tuple",
   and "dict" classes, as well as the "collections" module.

setattr(object, name, value)

   This is the counterpart of "getattr()".  The arguments are an
   object, a string and an arbitrary value.  The string may name an
   existing attribute or a new attribute.  The function assigns the
   value to the attribute, provided the object allows it.  For
   example, "setattr(x, 'foobar', 123)" is equivalent to "x.foobar =
   123".

class slice(stop)
class slice(start, stop[, step])

   Return a *slice* object representing the set of indices specified
   by "range(start, stop, step)".  The *start* and *step* arguments
   default to "None".  Slice objects have read-only data attributes
   "start", "stop" and "step" which merely return the argument values
   (or their default).  They have no other explicit functionality;
   however they are used by Numerical Python and other third party
   extensions. Slice objects are also generated when extended indexing
   syntax is used.  For example: "a[start:stop:step]" or
   "a[start:stop, i]".  See "itertools.islice()" for an alternate
   version that returns an iterator.

sorted(iterable, *, key=None, reverse=False)

   Return a new sorted list from the items in *iterable*.

   Has two optional arguments which must be specified as keyword
   arguments.

   *key* specifies a function of one argument that is used to extract
   a comparison key from each element in *iterable* (for example,
   "key=str.lower").  The default value is "None" (compare the
   elements directly).

   *reverse* is a boolean value.  If set to "True", then the list
   elements are sorted as if each comparison were reversed.

   Use "functools.cmp_to_key()" to convert an old-style *cmp* function
   to a *key* function.

   The built-in "sorted()" function is guaranteed to be stable. A sort
   is stable if it guarantees not to change the relative order of
   elements that compare equal --- this is helpful for sorting in
   multiple passes (for example, sort by department, then by salary
   grade).

   有关排序示例和简要排序教程，请参阅 Sorting HOW TO 。

@staticmethod

   将方法转换为静态方法。

   静态方法不会接收隐式的第一个参数。要声明一个静态方法，请使用此语法

      class C:
          @staticmethod
          def f(arg1, arg2, ...): ...

   "@staticmethod" 形式函数是一个 *decorator* 函数 - 参阅 Function
   definitions 中的函数定义说明，有更详细的信息。

   它可以在类（例如 "C.f()" ）或实例（例如 "C().f()" ）上调用。实例会
   被忽略，只需要类本身。

   Python中的静态方法与Java或C ++中的静态方法类似。另请参阅
   "classmethod()" ，用于创建备用类构造函数的变体。

   像所有装饰器一样，也可以像常规函数一样调用 "staticmethod" ，并对其
   结果执行某些操作。比如某些情况下需要从类主体引用函数并且您希望避免
   自动转换为实例方法。对于这些情况，请使用此语法:

      class C:
          builtin_open = staticmethod(open)

   有关静态方法的更多信息，请参阅标准类型层次结构中的文档 标准类型等级
   结构 。

class str(object='')
class str(object=b'', encoding='utf-8', errors='strict')

   返回一个 "str" 版本的 *object* 。有关详细信息，请参阅 "str()" 。

   "str" 是内置字符串 *class* 。更多关于字符串的信息查看 Text Sequence
   Type --- str。

sum(iterable[, start])

   Sums *start* and the items of an *iterable* from left to right and
   returns the total.  *start* defaults to "0". The *iterable*'s items
   are normally numbers, and the start value is not allowed to be a
   string.

   For some use cases, there are good alternatives to "sum()". The
   preferred, fast way to concatenate a sequence of strings is by
   calling "''.join(sequence)".  To add floating point values with
   extended precision, see "math.fsum()".  To concatenate a series of
   iterables, consider using "itertools.chain()".

super([type[, object-or-type]])

   Return a proxy object that delegates method calls to a parent or
   sibling class of *type*.  This is useful for accessing inherited
   methods that have been overridden in a class. The search order is
   same as that used by "getattr()" except that the *type* itself is
   skipped.

   The "__mro__" attribute of the *type* lists the method resolution
   search order used by both "getattr()" and "super()".  The attribute
   is dynamic and can change whenever the inheritance hierarchy is
   updated.

   If the second argument is omitted, the super object returned is
   unbound.  If the second argument is an object, "isinstance(obj,
   type)" must be true.  If the second argument is a type,
   "issubclass(type2, type)" must be true (this is useful for
   classmethods).

   There are two typical use cases for *super*.  In a class hierarchy
   with single inheritance, *super* can be used to refer to parent
   classes without naming them explicitly, thus making the code more
   maintainable.  This use closely parallels the use of *super* in
   other programming languages.

   The second use case is to support cooperative multiple inheritance
   in a dynamic execution environment.  This use case is unique to
   Python and is not found in statically compiled languages or
   languages that only support single inheritance.  This makes it
   possible to implement "diamond diagrams" where multiple base
   classes implement the same method.  Good design dictates that this
   method have the same calling signature in every case (because the
   order of calls is determined at runtime, because that order adapts
   to changes in the class hierarchy, and because that order can
   include sibling classes that are unknown prior to runtime).

   For both use cases, a typical superclass call looks like this:

      class C(B):
          def method(self, arg):
              super().method(arg)    # This does the same thing as:
                                     # super(C, self).method(arg)

   Note that "super()" is implemented as part of the binding process
   for explicit dotted attribute lookups such as
   "super().__getitem__(name)". It does so by implementing its own
   "__getattribute__()" method for searching classes in a predictable
   order that supports cooperative multiple inheritance. Accordingly,
   "super()" is undefined for implicit lookups using statements or
   operators such as "super()[name]".

   Also note that, aside from the zero argument form, "super()" is not
   limited to use inside methods.  The two argument form specifies the
   arguments exactly and makes the appropriate references.  The zero
   argument form only works inside a class definition, as the compiler
   fills in the necessary details to correctly retrieve the class
   being defined, as well as accessing the current instance for
   ordinary methods.

   For practical suggestions on how to design cooperative classes
   using "super()", see guide to using super().

tuple([iterable])

   Rather than being a function, "tuple" is actually an immutable
   sequence type, as documented in 元组 and Sequence Types --- list,
   tuple, range.

class type(object)
class type(name, bases, dict)

   With one argument, return the type of an *object*.  The return
   value is a type object and generally the same object as returned by
   "object.__class__".

   The "isinstance()" built-in function is recommended for testing the
   type of an object, because it takes subclasses into account.

   With three arguments, return a new type object.  This is
   essentially a dynamic form of the "class" statement. The *name*
   string is the class name and becomes the "__name__" attribute; the
   *bases* tuple itemizes the base classes and becomes the "__bases__"
   attribute; and the *dict* dictionary is the namespace containing
   definitions for class body and is copied to a standard dictionary
   to become the "__dict__" attribute.  For example, the following two
   statements create identical "type" objects:

   >>> class X:
   ...     a = 1
   ...
   >>> X = type('X', (object,), dict(a=1))

   See also Type Objects.

   在 3.6 版更改: Subclasses of "type" which don't override
   "type.__new__" may no longer use the one-argument form to get the
   type of an object.

vars([object])

   Return the "__dict__" attribute for a module, class, instance, or
   any other object with a "__dict__" attribute.

   Objects such as modules and instances have an updateable "__dict__"
   attribute; however, other objects may have write restrictions on
   their "__dict__" attributes (for example, classes use a
   "types.MappingProxyType" to prevent direct dictionary updates).

   Without an argument, "vars()" acts like "locals()".  Note, the
   locals dictionary is only useful for reads since updates to the
   locals dictionary are ignored.

zip(*iterables)

   Make an iterator that aggregates elements from each of the
   iterables.

   Returns an iterator of tuples, where the *i*-th tuple contains the
   *i*-th element from each of the argument sequences or iterables.
   The iterator stops when the shortest input iterable is exhausted.
   With a single iterable argument, it returns an iterator of
   1-tuples.  With no arguments, it returns an empty iterator.
   Equivalent to:

      def zip(*iterables):
          # zip('ABCD', 'xy') --> Ax By
          sentinel = object()
          iterators = [iter(it) for it in iterables]
          while iterators:
              result = []
              for it in iterators:
                  elem = next(it, sentinel)
                  if elem is sentinel:
                      return
                  result.append(elem)
              yield tuple(result)

   The left-to-right evaluation order of the iterables is guaranteed.
   This makes possible an idiom for clustering a data series into
   n-length groups using "zip(*[iter(s)]*n)".  This repeats the *same*
   iterator "n" times so that each output tuple has the result of "n"
   calls to the iterator. This has the effect of dividing the input
   into n-length chunks.

   "zip()" should only be used with unequal length inputs when you
   don't care about trailing, unmatched values from the longer
   iterables.  If those values are important, use
   "itertools.zip_longest()" instead.

   "zip()" in conjunction with the "*" operator can be used to unzip a
   list:

      >>> x = [1, 2, 3]
      >>> y = [4, 5, 6]
      >>> zipped = zip(x, y)
      >>> list(zipped)
      [(1, 4), (2, 5), (3, 6)]
      >>> x2, y2 = zip(*zip(x, y))
      >>> x == list(x2) and y == list(y2)
      True

__import__(name, globals=None, locals=None, fromlist=(), level=0)

   注解: This is an advanced function that is not needed in everyday
     Python programming, unlike "importlib.import_module()".

   This function is invoked by the "import" statement.  It can be
   replaced (by importing the "builtins" module and assigning to
   "builtins.__import__") in order to change semantics of the "import"
   statement, but doing so is **strongly** discouraged as it is
   usually simpler to use import hooks (see **PEP 302**) to attain the
   same goals and does not cause issues with code which assumes the
   default import implementation is in use.  Direct use of
   "__import__()" is also discouraged in favor of
   "importlib.import_module()".

   The function imports the module *name*, potentially using the given
   *globals* and *locals* to determine how to interpret the name in a
   package context. The *fromlist* gives the names of objects or
   submodules that should be imported from the module given by *name*.
   The standard implementation does not use its *locals* argument at
   all, and uses its *globals* only to determine the package context
   of the "import" statement.

   *level* specifies whether to use absolute or relative imports. "0"
   (the default) means only perform absolute imports.  Positive values
   for *level* indicate the number of parent directories to search
   relative to the directory of the module calling "__import__()" (see
   **PEP 328** for the details).

   When the *name* variable is of the form "package.module", normally,
   the top-level package (the name up till the first dot) is returned,
   *not* the module named by *name*.  However, when a non-empty
   *fromlist* argument is given, the module named by *name* is
   returned.

   For example, the statement "import spam" results in bytecode
   resembling the following code:

      spam = __import__('spam', globals(), locals(), [], 0)

   The statement "import spam.ham" results in this call:

      spam = __import__('spam.ham', globals(), locals(), [], 0)

   Note how "__import__()" returns the toplevel module here because
   this is the object that is bound to a name by the "import"
   statement.

   On the other hand, the statement "from spam.ham import eggs,
   sausage as saus" results in

      _temp = __import__('spam.ham', globals(), locals(), ['eggs', 'sausage'], 0)
      eggs = _temp.eggs
      saus = _temp.sausage

   Here, the "spam.ham" module is returned from "__import__()".  From
   this object, the names to import are retrieved and assigned to
   their respective names.

   如果您只想按名称导入模块（可能在包中），请使用
   "importlib.import_module()"

   在 3.3 版更改: Negative values for *level* are no longer supported
   (which also changes the default value to 0).

-[ 脚注 ]-

[1] 解析器只接受 Unix 风格的行结束符。如果您从文件中读取代码，请确
    保用 换行符转换模式转换Windows 或 Mac 风格的换行符。
