TOPIC 5: Python Lists
Completion requirements
5. Mixed Datatypes & List Indexing
Mixed Data Types
A list can also contain different data types in the same list.
Example:
list1 = ["abc", 34, True, 40, "male"]
print(list1)
Output:
['abc', 34, True, 40, 'male']
List Indexing
Every item in a list has an index number.
Indexing starts from 0.
Example:
thislist = ["apple", "banana", "cherry"]
| Item | Index |
| apple | 0 |
| banana | 1 |
| cherry | 2 |
To access an item, use its index number.
Example:
thislist = ["apple", "banana", "cherry"]
print(thislist[1])
Output:
banana