You can use a for in loop to get the elements of the array. colours = ["red","green","blue"] for colour in colours: print colour # red # green # blue However if you also need access to the position of the element in the array we can use a for in loop over a [...]
Posts Tagged ‘Array’
How to create an associative array in Python?
December 20th, 2010
No Comments
Associative arrays in Python are called dictionaries. # Dictionary with quoted or variable keys d1 = { "name":"donuts", "type":"chocolate", "quantity":10 } # Dictionary with fixed keys d2 = dict(name="donuts", type="chocolate", quantity=10) assert d1 == d2
