python functions Flashcards
remove whitespace from ‘ this sentence right here ‘
x = ' this sentence right here ' x = x.strip()
a string is my_string = 'abcdefg' get: 'c' 'cde' 'fg' 'bcdef'
my_string[2]
my_string[2:5]
my_string[-2:]
my_string[1:-1]
get index within a list of list item x
my_list.index()
get count of a specific item x within a list
my_list.count(x)
add an item to list end
my_list.append(x)
remove first matching item from list
my_list.remove(x)
reverse a list
my_list.reverse()
function to remove item from list given the index or you want to remove from end, returning the item from the function
my_list.pop(index or if none, removes last item)
insert item to list at specific index
my_list.insert(index, x)
sort a list
my_list.sort()
uppercase a string
my_string.upper()
lowercase a string
my_string.lower()
get count of item in list or substring within string
my_string.count(‘x’)
my_list.count(x)