Skip to main content

Section 3.12 Some Extra String Methods (Optional)

In addition to what we have seen in the previous section, the following table provides a summary of some other string methods. You don’t have to memorize them.
Table 3.12.1.
Method Parameters Description
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
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
rfind item Returns the rightmost index where the substring item is found, or -1 if not found
find item Like index except returns -1 if item is not found
rindex item Like rfind except causes a runtime error if item is not found
You should experiment with these methods so that you understand what they do. Note once again that the methods that return strings do not change the original. You can also consult the Python documentation for strings
 1 
https://docs.python.org/3/library/stdtypes.html#string-methods
.
You have attempted of activities on this page.