Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python memoryview() Function

Python memoryview() Function

Python built-in function Python built-in function


Description

memoryview() The function returns a memory view object of the given argument.

A memory view object wraps data that supports the buffer protocol, allowing Python code to access it without copying the object.

Syntax

memoryview syntax:


memoryview(obj)

Parameter Description:

Return Value

Returns a list of tuples.

Example

The following examples demonstrate how to use memoryview:

Python 2.x application:

v

=

memoryview

(

'

abcefg

'

)

v

[

1

]

'

b

'

v

[

1

]

'

g

'

v

[

1

:

4

]

<

memory

at

0

x77ab28

v

[

1

:

4

]

.

tobytes

(

)

'

bce

'

Python 3.x application:

v

=

memoryview

(

bytearray

(

"

abcefg

"

,

'

utf-8

'

)

)

print

(

v

[

1

]

)

98

print

(

v

[

1

]

)

103

print

(

v

[

1

:

4

]

)

<

memory

at

0

x10f543a08

print

(

v

[

1

:

4

]

.

tobytes

(

)

)

b

'

bce

'

Python built-in function Python built-in function