memoryview() 函數返回給定參數的內存查看對象(Momory view)。
語法
memoryview 語法:memoryview(obj)
參數說明:obj -- 對象
返回值:返回元組列表。
英文文檔:
class memoryview(obj)
memoryview objects allow Python code to access the internal data of an object that supports the buffer protocol without copying.
Create a memoryview that references obj. obj must support the buffer protocol. Built-in objects that support the buffer protocol include bytes and bytearray.
說明:
1. 函數功能返回內存查看對象,實際上是內存查看對象(Momory view)的構造函數。
2. 所謂內存查看對象,是指對支持緩沖區協議的數據進行包裝,在不需要復制對象基礎上允許Python代碼訪問。
3. Python內置對象中支持緩沖區協議的對象有bytes和bytearray。
示例
>>> v = memoryview(b'abcefg')>>> v[1]98>>> v[-1]103>>> v[1:4]<memory at 0x7f3ddc9f4350>>>> bytes(v[1:4])b'bce'
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林站長站。
新聞熱點
疑難解答