Python 3.4 - Array Module

Arrays are much like lists but they are confined to one type of data.  The example linked needs parentheses around the print statements, but you can see below some of the differences between lists and arrays:

import array

a = array.array("B", range(16)) # unsigned charb = array.array("h", range(16)) # signed short
print (a)
print (repr(a.tostring()))

print (b)
print (repr(b.tostring()))

/Users/mattfassnacht/PycharmProjects/untitled6/venv/bin/python /Users/mattfassnacht/PycharmProjects/untitled6/functions.py
array('B', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])
b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'
array('h', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])
b'\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\t\x00\n\x00\x0b\x00\x0c\x00\r\x00\x0e\x00\x0f\x00'

Process finished with exit code 0


http://effbot.org/librarybook/array.htm

Comments

Popular posts from this blog

Python 3.4 - Caesar Cipher

UML - Use Case Diagram