Finding out more about string methods

Tip For more information on string methods, type help(str) at the Python prompt.

The string methods work with both regular strings and Unicode strings (see the upcoming section, "Unraveling Unicode"). They include the following types of actions:

• Case manipulation (capitalize, upper, lower, swapcase, title)

• Counting (count—number of times substring is in string)

• Manipulating text encoding (encode, decode)

• Search and replace (find, replace, rfind, index, rindex, translate)

• Tests that return Boolean (True or False) values (startswith, endswith, isalnum, isalpha, isdigit, islower, isspace, istitle, isupper)

• Joining and splitting (join, partition, rpartition, split, splitlines)

• Formatting (center, ljust, lstrip, rstring, rjust, strip, zfill, expandtabs)

Tip The Cheat Sheet attached to the front of this book briefly describes how most of the above methods work.

Was this article helpful?

0 0

Post a comment