In this blog, I am going to give you some more information about lists and tuples. Hopefully you fully understand what both are and when to use them after this blog. So let’s get started.
Lists
The first thing that I am going to explain is a list. A list is very easy to make in Python. First you need to define your list, and that is just possible with giving it a name and then ‘=’. After that you open the list with a square bracket and you type the content of your list, divided by commas. The last step is to close the list with a square bracket. If the content of your list is just words or letters for example, you have to put it between apostrophes. If the content of your list is already defined, it is enough to only separate it with commas. See below for my example:

A list has a couple of important characteristics of whom I am going to explain a couple. The first one is that a list is always ordered. If you change the order of the elements of the list, it is a different list according to Python.
A list can also contain any kind of elements. You can use, as seen here above, letters or defined numbers, but you can even use functions and numbers, Besides that, you can make the list as long as you want and even repeat the same element.
Another thing is that you can always access individual elements from a list. Every element in a list has an index number, the place where it stands in the list. So in the example above here, b has the index 0, c has the index 1, end so on. You can call these elements individually by typing the name of your list followed by the index number in square brackets:

Thalast one that I am going to discuss here is the fact that a list is mutable. Most of the data types in Python are not mutable, but the list is one of the easiest that is. That a list is mutable means that you can always delete, add or changes individual elements in the list.
In the example below here, I first changed index number 2 in the list to 5, so d–>5 (list[2]=5). After that I deleted index number 4 of the list (del list[4]). The last thing that I did was deleting index number 2 until 4 (5,e,f) and placing in that spot 88,99,100,200 (list[2:4]=[88,99,100,200]).

For more information about characteristics of list, you can consult this site: https://realpython.com/python-lists-tuples/ .
Tuples
So okay, now over to the tuples. Tuples are actually quite identical to lists, but they differ on two things:
– To define a tuple, you need to put the content in parenthesis instead of the square brackets for a list. Attention! To call individual elements of a list you still need to use square bracktes (see below).
– Tuples are immutable in comparison to lists.

All the other characteristics are exactly the same for tuples and lists.
So when a tuple and when a list?
When to use a list is quite obvious. You need to use a list when it is mandatory to make changes or add things in the list. So for example in WSQ07, we had to ask ten different numbers from our program and after that we had to sum all those numbers. My solution was to ask ten different numbers and add them one for one in a list. This would not have been possible with a tuple, because you can’t add numbers in a tuple.
So when to use a tuple?
– If you already know in beforehand that the content of a list/tuple is not meant to change, it can be useful to use a tuple. In that way, you make sure that the content is definitely not going to change.
– The program execution is faster with tuples instead of lists, but you only mention that with really big data.
– In one of the following blogs we are going to discuss dictionaries. In dictionaries require components that are not possible to change. So in that case you can only use tuples for the content of dictionaries.
Hopefully you gained a lot of new information out of this blog and good luck with bringing it in practice!