The importance of variables in any programming language can’t be emphasised enough. Even if you are a novice, the chances are good that you will have been using variables for quite a while now.

They are the cornerstone of any language and without them we would not be able to accomplish much of anything. However, most of you up until this point have probably only been working with standard variables, variables which can hold single values such as an integer, a single character, or a string of text.

In this tutorial we are going to take a look at a more special type of variable called an array. Arrays can seem quite daunting at first glance but once you get used to working with them you will wonder how you ever managed to program without them.

The reason arrays are special is because they can hold more than one value. Think about this: say you create a variable which contains a line of text like the code below:

myString = “This is a string”

Python makes it easy for us to work with strings as single entities but under the hood your computer treats strings like an array. It sets aside space for each character in memory, and when your application needs to use that string, it will retrieve each character to recreate the whole string.

In other languages an array can be referred to under different names such as an object or a collection. In python it is known as a list, and the best way to get a feel for these special variables is to actually use them.

myList = [‘a’, “string ”,1]

print myList[0]

If you’re feeling a little confused by the code above, don’t worry here is how it works. On the first line we create a variable called myList which contains three different elements; a single character, a string and an integer. The square brackets are important because without them Python would not know that you wanted to create a list.

The second line is where things get interesting because you will notice that we use the print statement and then our variable with the number zero in square brackets next to it.

If you look again at the first line of code you will notice that we create three elements. When working with lists and arrays in general you always start counting from 0. So if you had a list with say ten elements, then you would count from 0 to 9. This is an important concept to keep in mind, especially when you start to use lists within loops which will be covered in another tutorial.

So, you have had a brief introduction to working with lists in Python and although it was only two lines of code, you should see how they can be very useful in your future projects. As you become more advanced you will find that you simply cannot perform certain actions without the use of lists.