How to Use memoryview() Function in PythonPython Basics


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

Example

#!/usr/bin/python
# -*- coding: UTF-8 -*-

a = memoryview(bytearray("123ABC", 'utf-8'))
#return the Unicodes of the characters "123ABC"
print(a[0])
print(a[1])
print(a[2])
print(a[3])
print(a[4])
print(a[5])

Output:

49
50
51
65
66
67

Syntax

memoryview(obj)

Parameters

Name Description
obj Object whose internal data is to be exposed.

Return Value

It returns a memory view object of the given object.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us