python内置方法、模块讲解(三)

  • 2016-02-23 00:10:44
  • 1269
  • 0

八、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类

(以下省略)

阅读更多

python内置方法、模块讲解(二)

  • 2016-02-21 23:02:52
  • 1159
  • 0

四、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内置方法、模块讲解(一)

  • 2016-02-21 19:29:28
  • 1159
  • 0

  python 哪些内置的方法、模块呢? 可以​通过以下方式查看如下:

  

  可以看出以大写字母以及下划线开头那些主要为各种错误类别、警告、信息之类, 在我们实际写代码过程中,很少主动去调用。所以, 接下来我将从abs方法开始讲解。

(以下省略)

阅读更多