The memoryview() function returns a memory view object of the given argument. It is used to get a memory view object from a specified object. It is the safe way to expose the buffer protocol in Python. It allows us to access the internal buffers of an object by creating a memory view object.
- obj: It is used for internal data processing.
- Its give memoryview object of the given argument.
It provides a way to access the internal data of an object. This internal data is a memory array or a buffer. It allows one object to expose its internal data and the other to access those buffers without intermediate copying.
It is only accessible to us at C-API and not using our normal code base.
byte_array = bytearray('abc', 'utf-8') x = memoryview(byte_array) print(x) print(x[2:6]) print(x[1:3])
97 <memory at 0x7fc429536ac0> <memory at 0x7fc429536ac0>