Python Flashcards
(16 cards)
append()
Adds element to end of list
mylist.append(“Apple”)
clear()
Removes all elements from list
mylist.clear()
count()
Counts elements in list
mylist.count()
index()
Returns first index number of element in a list or string
remove()
Removes 1st item of specified value
pop()
Removes element from the specified position from a list or dictionary.
List.pop(2)
insert()
Inserts at a specified position in a list
mylist.insert(2, “Apple”)
reverse()
Reverses the list in place
mylist.reverse()
len()
Gives length
sort()
Sorts lists alphabetically in place
split(), in a string. Separates by what? What is the whole command string
Puts elements into a list. Separates by spaces or what is put in parentheses. List = “this is a string”
List.split()
Print every other starts on which element
The first element
Sort and reverse commands issue
Does it in place so you can’t assign to a new name because they only return none
range () options
One number, or a range of numbers with steps. Ex…for n in range(start_num, end_number,steps)
Sorted()
To sort a list not in place. Will not change the original list. This allows a new list to be saved.
Reversed ()
Reverses but doesn’t change original. Can be used to create a new list.