Module 4: Data Collections and Functions
Lists
Lists are ordered, mutable (changeable) collections of items. Items can be of different types.
- Creating:
my_list = [1, "hello", 3.14]
- Accessing: Use index (starts at 0).
my_list[0]
is1
. - Slicing: Get a sub-list.
my_list[1:3]
is["hello", 3.14]
. - Modifying:
my_list[1] = "world"
- Common Methods:
append(item)
,insert(index, item)
,pop(index_optional)
,remove(item)
,sort()
,len(list)
(gets length).