Show the most commonly asked-about Python string methods in one script.
Interviewers usually reach for the same short list of methods. They ask about the cleaning methods, the searching methods, and the methods that split and join text.
s = ' Hello, World '
print(repr(s.strip()))
print(s.lower())
print(s.replace('World', 'Python'))
print(s.split(', '))
print('-'.join(['a', 'b']))
print(s.startswith(' '))
print(s.find('World'))
print(s.count('l'))
print(repr(s.title()))
print(s.isdigit())
Several of those results are worth reading carefully. The find call returns 9, which is the position of the letter W, because the two leading spaces are counted as well. The count call returns 3, which is two letter l characters in Hello and one in World. The title() call looks as if it should change something, but the words are already capitalised, so it gives back the same text.
The cleaning methods come in pairs that are worth knowing. strip() removes whitespace from both ends, and lstrip() and rstrip() remove it from one side only. The argument is optional, and when you give one it removes that character instead of whitespace, so s.strip(',') removes commas from the ends.
The searching methods fall into three families. find() and index() return a position, and they differ in what happens when there is no match. index() raises a ValueError while find() returns -1. The in operator tests membership and gives you a boolean. The startswith() and endswith() methods accept a tuple of alternatives, so filename.endswith(('.csv', '.tsv')) checks both of them without an or.
Every membership test is case-sensitive, and that is the most common source of a wrong answer in an interview. Python has no built-in case-insensitive contains, so the usual habit is to lowercase both sides before you compare them.