八、buffer类
1、定义:
buffer(object[, offset[, size]]) The object argument must be an object that supports the buffer call interface (such as strings, arrays, and buffers). A new buffer object will be created which references the object argument. The buffer object will be a slice from the beginning of object (or from the specified offset). The slice will extend to the end of object (or will have a length given by the size argument).
2、解释:输入参数object必须支持缓存调用接口(如字符串、数组、buffer)。用来创建一个引用object参数的新buffer对象, 这个buffer可以是以object参数的一个切片,切片所取的位置由offset、size参数决定。
3、举例:
>>> s = 'Hello world' >>> t = buffer(s, 5, 5) >>> t <read-only buffer for 0x000000000282FE10, size 5, offset 5 at 0x00000000029BBED8> >>> print t worl >>> t = buffer(s, 5, 6) >>> print t world
九、bytearray类
(以下省略)
四、apply方法
1、定义:
apply(...) apply(object[, args[, kwargs]]) -> value Call a callable object with positional arguments taken from the tuple args, and keyword arguments taken from the optional dictionary kwargs. Note that classes are callable, as are instances with a __call__() method. Deprecated since release 2.3. Instead, use the extended call syntax: function(*args, **keywords).
2、解释:根据有序的元组、字典调用一个可调用的对象, 注:拥有__call__()方法的实例是可调用的, 生成实例的类也是有可调用的。
3、举例:
>>> def test(a, b): ... print a, b ... >>> apply(test, ('hello', 'world')) hello world
五、basestring类型
(以下省略)
python 哪些内置的方法、模块呢? 可以通过以下方式查看如下:
可以看出以大写字母以及下划线开头那些主要为各种错误类别、警告、信息之类, 在我们实际写代码过程中,很少主动去调用。所以, 接下来我将从abs方法开始讲解。
(以下省略)
Copyright © 2021.aoyanming个人博客站