Lists are a widely used data structure that can hold multiple values. Let's look at some features of lists:
- To make a list, we use square brackets, [].
Example: my_list = [1, 2, 3]. - Lists can hold any combination of numeric types, strings, Boolean types, tuples, dictionaries, or even other lists.
Example: my_diverse_list = [51, 'Health', True, [1, 2, 3]]. - Lists, like strings, are sequences and support indexing and slicing.
For example, in the preceding example, my_diverse_list[0] would equal 51. my_diverse_list[0:2] would equal [51, 'Health']. To access the 3 of the nested list, we can use my_diverse_list[3][2]. - Lists are mutable (unlike strings and tuples), meaning that we can change individual components using indices.
For example, if we entered the my_diverse_list[2] = False command, our new my_diverse_list would be equal to [51, 'Health', False, [1, 2, 3]] .
Notable advantages of lists for analytics include their vast array of helper methods, such as append(), extend(), and join(), and their interchangeability with the pandas and numpy data structures.