A string method is a function associated with Python’s string type. Call it by placing the string first, followed by a dot, the method name, and parentheses for arguments. section 4.3.4
String methods support several practical text-processing tasks:
- Check text, such as whether it is uppercase, numeric, or made only of letters and numbers. section 4.3.4
- Convert capitalization, search text, format text, or replace specified substrings. section 4.3.4
Cleaning a phone number
A function can call replace() repeatedly to remove unwanted characters: phone_number.replace('(', ''), then replace ')' and '-'. Each call returns text with the selected substring replaced by the supplied replacement. section 4.3.4
>>> 'abc'.isupper() #1 False >>> 'Abc'.isupper() False >>> 'ABC'.isupper() True >>> 'abc'.isdigit() #2 False #2 >>> '345bc'.isdigit() #2 False #2 >>> '345'.isdigit() #2 True #2 >>> 'abc6'.isalnum() #3 True #3 >>> 'abc def'.isalnum() #3 False #3 >>> 'abcdef#'.isalnum() #3 False #3
Compare isupper(), isdigit(), and isalnum() with strings containing different capitalization, digits, spaces, and symbols. section 4.3.4
When an explanation of string methods is vague, ask specifically what each method does, what arguments it receives, and how it changes the result. section 4.4

