Data Structures

This lesson discusses the common built-in data structures of Python used for data processing.

Lists in Python #

As mentioned in the previous section, lists are a useful data structure in Python. Lists are ordered, changeable, and allow for duplicates. You create a list with the [].

We can slice a list. Slicing means to extract a part of the list. When slicing, the first number is included in the return set while the last number is not. For example:

p1 = [1,2,3,4,5,6,7,8,9,10]
p2 = p1[0:5]

The list p2 will be [1,2,3,4,5]. Because we’ll start from 0th index of p1 and will stop at 5th index slicing all the elements till 4th index.

Note: You can also write p2 = p1[0:5] as p2 = p1[:5].

Here are many of the ways you can use lists.

Please take the time to review the comments and the print statements to understand what each line is doing. You can tie the print statements to the code by the lines printed above the results in the output.

Get hands-on with 1200+ tech skills courses.