1/28
Vocabulary flashcards covering string operations, methods, immutability, slicing, and tokenization in Python as presented in Chapter 8.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Sequences
A category of data types in Python; because strings belong to this category, many tools that work with other sequence types also work with strings.
Indexing
A method to access individual characters in a string where each character has a position number starting at 0. Format: character=my_string[i].
IndexError
An exception that occurs if you try to use an index that is out of range for the string, likely happening when a loop iterates beyond the end of the string.
len(string) function
A function used to obtain the length of a string, which is useful to prevent loops from iterating beyond the end of the string.
Concatenation
The process of appending one string to the end of another using the + operator or the augmented assignment operator +=.
Immutable
A characteristic of strings meaning they cannot be changed once they are created; operations like concatenation create a new string rather than modifying the existing one.
Slice
A span of items taken from a sequence, also known as a substring. Format: string[start:end].
in operator
An operator used to determine whether one string is contained in another string. General format: string1 in string2.
not in operator
An operator used to determine whether one string is not contained in another string.
isalnum()
Returns true if the string contains only alphabetic letters or digits and is at least one character in length; returns false otherwise.
isalpha()
Returns true if the string contains only alphabetic letters and is at least one character in length; returns false otherwise.
isdigit()
Returns true if the string contains only numeric digits and is at least one character in length; returns false otherwise.
islower()
Returns true if all of the alphabetic letters in the string are lowercase and the string contains at least one alphabetic letter.
isspace()
Returns true if the string contains only whitespace characters (spaces, newlines \text{\n}, and tabs \text{\t}) and is at least one character in length.
isupper()
Returns true if all of the alphabetic letters in the string are uppercase and the string contains at least one alphabetic letter.
lower()
Returns a copy of the string with all alphabetic letters converted to lowercase.
lstrip()
Returns a copy of the string with all leading whitespace characters (spaces, newlines \text{\n}, and tabs \text{\t}) removed from the beginning.
rstrip()
Returns a copy of the string with all trailing whitespace characters removed from the end of the string.
strip()
Returns a copy of the string with all leading and trailing whitespace characters removed.
upper()
Returns a copy of the string with all alphabetic letters converted to uppercase.
endswith(substring)
A search method that returns True if the string ends with the specified substring; otherwise returns False.
find(substring)
Searches for a substring within the string and returns the lowest index of the substring, or −1 if the substring is not contained in the string.
replace(old, new)
Returns a copy of the string where every occurrence of the string 'old' is replaced with the string 'new'.
startswith(substring)
A search method that returns True if the string starts with the specified substring; otherwise returns False.
Repetition operator
The × symbol (∗) when applied to a string (left operand) and an integer (right operand) to join multiple copies of the string together.
split method
A method that returns a list containing the words in the string, using a space as the default separator or a specific character passed as an argument.
Tokens
Substrings that are separated by a special character within a larger string.
Delimiter
The separating character used in a string to distinguish between individual tokens.
Tokenizing
The process of breaking a string into tokens and storing them as individual items.