Lists and Tuples

--Originally published at Hackerman's house

chema

I review this topic with my good friend Sebastian Cedeño, we read a lot about this topic and made this really cool post. So bad that I had to finish it and upload it, so im doing this really late in friday night. There is a little bit of regreat in this words, but i’m also happy that I could finish this partial just as planned. Also check out Cheba’s blog: https://chebasquared.wordpress.com/

Lists and Tuples are sequenced types of data so called because they behave like a sequence.  This type of data is different than the numeric data because they are made of smaller elements that are put together. The elements that are inside a List or a Tuple can be almost any type of data, like a string, a numeric value even another list or tuple.

Define a list is really simple. Its similar to a string just that in this case we dont use ”, we use  square brackets. []

ListExample = [2, “Chema “, 3, “Paco “, (“Perro”, “Gato”)]

A tuple is almost the same as a list, the main difference between this two is that a list can be updated and modified, and a tuple cant be moddified once it has been defined. This means that the original values that are inside a Tuple will be there forever. Also the way that they are defined is a little bit different. While lists use square brackets, Tuples use parenthesis ().

TupleExample = (6, 9, “Clase “, [“Tarde “, “Dr. Strange “])

You can do many things with these type of data, for example you can select a certain element that is inside the list or tuple. In the following example you will get the first element on the list, the first element has a

index.

ListExample [0]

You can also obtain how many  elements a list contain. The next code will obtain the number of elements that the tupple contain, it doesn’t matter which type of data is inside the tupple. Also is worth noticing that a list inside a tupple will only be counted as one element, it doesn’t matter how many elements are inside that list.

len(TupleExample)

You can check this links if you want to know more about this topic.

https://docs.python.org/3.3/tutorial/datastructures.html

http://www.openbookproject.net/books/bpp4awd/ch03.html