Lists and Collections

Manipulating Varables

Lists and Collections

🙋 Need help? Ask an expert now!

First up: Collections

Storing Data in a python list

Once you have had the opportunity to use each of these data types in python, you can hold these variables in a multitude of data structures. One of the most useful data structures that you will find are lists.

List can contain both numbers and strings and can hold many of each. In general, you want to make sure that you do not name your list: 'list' as this will lead to errors in the future. A few more example of putting together lists is below:

# list with Numbers lst1 = [1,2,3,4] # list with strings lst2 = ['strings', 'can', 'go', 'in', 'here','too'] # list with strings and numbers lst3 = [1,2,'string','another string'] # Print each out: print(lst1) print(lst2) print(lst3)

In the future, we will explore indexing more, but in python index always start at 0 and you can access any element of a list using its index.

As well, we will explore other methods for holding your data including tuples, sets, and dictionaries

Edit Me on GitHub!