9.5. String Methods
ae
9.5. String Methods
ae
10.14. List Methods
ad
and you can fill in the name of the person greeted, and combine given text with a chosen insertion. We use this as an analogy: Python has a similar construction, better called fill-in-the-braces. The string method format, makes substitutions into places in a string enclosed in braces. Run this code:
add
upper none Returns a string in all uppercase lower none Returns a string in all lowercase capitalize none Returns a string with first character capitalized, the rest lower strip none Returns a string with the leading and trailing whitespace removed lstrip none Returns a string with the leading whitespace removed rstrip none Returns a string with the trailing whitespace removed count item Returns the number of occurrences of item replace old, new Replaces all occurrences of old substring with new center width Returns a string centered in a field of width spaces ljust width Returns a string left justified in a field of width spaces rjust width Returns a string right justified in a field of width spaces find item Returns the leftmost index where the substring item is found, or -1 if not found rfind item Returns the rightmost index where the substring item is found, or -1 if not found index item Like find except causes a runtime error if item is not found rindex item Like rfind except causes a runtime error if item is not found format substitutions Involved! See String Format Method, below
ad