List definition and what can be in a list
3 Properties of List
List Syntax
list_variable = [‘Item1’ , ‘Item2’ , ‘Item3’ , ‘Etc….’]
Empty List Syntax
empty_list = [ ]
empty_list = list( )
3 general rules for indexing
Get FIRST indexed item from a list syntax
list_variable[0]
Negative Index def + syntax to get LAST item
-Used to identify list item’s position relative to the end of a list
list_variable[-1]
Length of a list syntax
len(list_variable)
Slicing Format and explanation
list_variable[start : end]
Slice to get index item 3 until the end
list_variable[2:]
Slice to get item 5 until the front
list_variable[: 5]
^have to start 1 AFTER whatever you want
Add items to a list options
append( )
insert( )
append( ) Syntax + where item goes
list_variable.append(‘New Item’)
Goes to end (highest index) of the list
insert( ) Syntax + where item goes
list_variable.insert(index , “New Item”)
Goes to designated position in index
Discard items from a list options
remove( )
pop( )
remove( ) Syntax + how it works
list_variable.remove(“Item”)
Removes 1st (lowest index value) instance of this item, if there are multiples whichever has lowest index is removed
pop( ) Syntax + how it works
pop(index)
Removes the indexed value from list and prints it
Change an element in a list syntax + what it does
list_variable[index#] = “New Value”
Replaces existing index value with whatever is on the right hand side of the index