Python lists are a versatile and common data types. You can store a sequence of elements (numbers, strings, or even other lists) in order and manipulate them easily.
Lists are defined with square brackets and the elements are separated by commas.
myList = [1 ,2, 3, 4]
You can also create an empty list by not putting any values between the square brackets. This is useful for when you need to create a list within a function; define an empty list beforehand and then sequentially add to it within the function.
emptyList = []
You can also use
range()
to create a range object. It takes up to three arguments and has the syntax of
range(start, stop+1, step).
Use
list()
to convert this range object into a list.
myList = list(range(1,11,1)) # Creates a list of numbers 1-10
myList = list(range(2,101,2)) # Creates a list of even numbers 2-100