String Slicing
You can isolate parts of a string using slice notation. my_str[start:end]
e.g. if my_str is Boggle, then my_str[0:3] outputs Bog.
Common slicing operations (table)
Stride
[0, 10, 1]
This determines how much the program will increment the index after reading each element.
Alignment Characters (<, >, ^)
These characters can be used to determine how a value will be aligned within the width of the field.
What are fill characters?
These are used to fill up empty space within the field width.
Floating-point Precision
Using an f string you can tell the program how many decimals (how precise) a float value can be.
finding and replacing string values:
replace(old, new)
This returns a copy of the string with all the occurances of the substring “old” will be replaced by the string “new”
Finding and replacing String values:
replace(old, new, count)
This also replaces all “old” with “new” BUT only replaces the first count occurrences of old.
Common methods for finding characters in strings (table)
String comparisons (table)
Other methods to check a strings value (table)
Transforming or creating new string methods (table)
split()
This method spilts a string into a list of tokens so that each token becomes a substring that forms a part of a larger string.
separator
These are characters that indicate where to split the string into tokens.
join()
This is a string method that does the opposite of split().