Chapter 8 Flashcards
Concatenation
Appending one string to the end of another string.
Slice
Span of items taken from a sequence; also known as substring.
in operator
You can use the in operator to determine whether one string is contained inside another string.
not in operator
You can use the not in operator to determine whether one string is NOT contained inside another string.
String methods
Strings in Python have many types of methods, divided into different types of operations. General format:
stringvar.method(argument)
endswith(substring)
Checks if the string ends with substring. Returns True or False.
startswith(substring)
Checks if the string starts with substring. Returns True or False.
find(substring)
Searches for substring within the string. Returns lowest index of the substring, or if substring is not found, returns -1.
replace(old, new)
Returns a copy of the new string where old is replaced with new.
Repetition operator (*)
Makes multiple copies of a string and joins them together. General format:
string_to_copy * n
split method
Returns a list containing the words in the string. By default, spaces are used as separators. Can specify a different separator by passing it as an argument, e.g. ‘/’.