Python among the array array of objects

Computer assigned a contiguous memory array to support random access to the array; 
since the address on the item numbers are continuous, an array by an address derived by adding the two values, and the array base address forthcoming adding the offset address entry.
The base address of the array is the machine address of the first item of the array. Offset address of an item its index is equal to the number of memory cells multiplied by a required item in the array represents a constant (in python, this value is always 1)

import array
#array module is an efficient storage array type implemented python. It is similar list, but all the members of the array must be of the same type, in the creation of the array, to determine the type of the array

array.array # (TypeCode, [initializer of]) - TypeCode: the element type code; initializer: initializer, if the array is empty, omitted initializer
arr = array.array('i',[0,1,1,3])
print(arr)

array.typecodes # - Module Properties
Print ( ' \ n-outputs a string containing all available types of code: ' )
print (array.typecodes) # Note the module name of the caller is not an object

array.typecode # - Object Properties
Print ( ' \ n-type code for creating an output array of characters: ' )
print(arr.typecode)

array.itemsize # - Object Properties
Print ( ' \ n the number of elements of the output array: ' )
print(arr.itemsize)

array.append # (the X-) - Object Methods
Print ( ' \ n-a new value to the end of the array: ' )
arr.append(4)
print(arr)

array.buffer_info # () - Object Methods
Print ( ' \ n-number of the acquired address in the memory array, the element in the form of a tuple (address, length) Returns: ' )
print(arr.buffer_info())

array.count # (the X-) - Object Methods
Print ( ' \ n-1 acquisition element number appearing in the array: ' )
print(arr.count(1))

array.extend # (Iterable) - Object Methods: iterables Yuan Xu appended to the end of the array, two combined sequences
Print ( ' \ n-element iterative object may be appended to the sequence of the end of the two sequences, consolidated data: ' )
# Note: Additional elements consistent with the numerical value element type must call the object's type
_list = [5,6,7]
arr.extend(_list)
print(arr)

array.fromlist # (List) - Method Object: The elements of the list is appended to the array, corresponding to X for in List: a.append (X)
Print ( ' \ n-element in the list is appended to the array, corresponding to X in List for: a.append (X): ' )
arr.fromlist(_list)
print(arr)

array.index # (x) - Object Method: returns the minimum index of the array x
Print ( ' \ n-Returns an array of the smallest subscript 1: ' )
print(arr.index(1))

array.insert # ( . 1 ) - Object Method: in Table I (a negative value indicates inverse number) prior to insertion of the value of x
Print ( ' \ n-following Table 1 (a negative value indicates inverse number) before inserting 0 values: ' )
arr.insert(1,0)
print(arr)

Array.pop # (i) - Object: Remove the item with index i, and returns it
Print ( ' \ the n-delete index entries 4 and return it: ' )
print(arr.pop(4))
print(arr)

array.remove # (x) - object method: Delete the first occurrence of an element x
Print ( ' \ the n-delete element 5 first appears: ' )
arr.remove(5)
print(arr)

Array.reverse # () - Object Method: Reverse array element values
Print ( ' \ n-arr array elements in reverse order: ' )
arr.reverse()
print(arr)

# Array.tolist (): the array into a list (list) with the same elements
Print ( ' \ n-converts the array arr as to have the same list of elements: ' )
li = arr.tolist()
print (li)

Output:

D:\python\test0611\venv\Scripts\python.exe D:/python/test0611/test.py
array('i', [0, 1, 1, 3])

Comprising an output code string types are available:
bBuhHiIlLqQfd

 Output type code used to create an array of characters:
i

The number of elements of the output array:
4

A new value to the end of the array:
array('i', [0, 1, 1, 3, 4])

Acquiring an address in the memory array, the number of elements in the form of a tuple (address, length) Returns:
(2325235347184, 5)

Gets the number of elements in the array 1 appears:
2

The iterables sequence of elements attached to the end of the data, merging two sequences:
array('i', [0, 1, 1, 3, 4, 5, 6, 7])

The elements in the list is appended to the array, corresponding to X for in List: a.append (X):
array('i', [0, 1, 1, 3, 4, 5, 6, 7, 5, 6, 7])

Returns an array of the smallest subscript 1:
1

In Table 1 (a negative value indicates inverse number) before inserting the value 0:
array('i', [0, 0, 1, 1, 3, 4, 5, 6, 7, 5, 6, 7])

Delete the item with index 4, returning it:
3
array('i', [0, 0, 1, 1, 4, 5, 6, 7, 5, 6, 7])

Element 5 to delete the first occurrence of:
array('i', [0, 0, 1, 1, 4, 6, 7, 5, 6, 7])

The order of the array elements in the reverse arr:
array('i', [7, 6, 5, 7, 6, 4, 1, 1, 0, 0])

The array arr as to convert the list with the same elements:
[7, 6, 5, 7, 6, 4, 1, 1, 0, 0]

Process finished with exit code 0

All types of numeric character code table:

 

Guess you like

Origin www.cnblogs.com/geeksongs/p/11007396.html