Lists in Python

Wednesday 23 December 2009

Lists in Python work the same way as arrays in many other languages.
The syntax is really simple and friendly.
Here is a list declaration:

myList = []

Appending data is also easy:


Initialising lists in one strike is also friendly:

myList = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

Parsing an array is really simple, the for loop does all the job:

for val in myList:
  print val

Will print each value "val" from our list.

For more informations about the lists in python, don't hesitate to chech the python reference page here :

TAGS: python,programming,lists in python