Python is a high-level programming language that provides functionalities for several operations. The
array module comes with various methods to manipulate array data structures.
buffer_info() function is used to get the memory address and the length of the buffer that holds the array’s contents.
(address, length) = arr.buffer_info()
This function does not take in any arguments.
buffer_info() returns a tuple, which contains the memory address and the length of the buffer that holds the array’s contents in the form (address, length).
#import module from array import array #initialize arrays array_one = array("i", [1, 2, 3]) array_two = array("i", [6, 7, 8, 9]) array_three = array("f", [6.4, 2.2, 8.7, 9.0, 10.5]) array_four = array("f", [12.5, 16.1, 7.3]) #print buffer info print (array_one) print (array_one.buffer_info()) print ("\n") print (array_two) print (array_two.buffer_info()) print ("\n") print (array_three) print (array_three.buffer_info()) print ("\n") print (array_four) print (array_four.buffer_info())
In the above code, the
array module is first imported. We then initialize two arrays with the data types
integer in lines 5-6, and two arrays of data type
float in lines 7-8. Each array is printed along with its buffer information in the form (address, length) in lines 11-24.
View all Courses