Chapter 9. Strings and Regular Expressions
Python supports plain and Unicode strings extensively, with
statements, operators, built-in functions, methods, and dedicated
modules. This chapter covers the methods of string objects, talks
about string formatting, documents the string,
pprint, and repr modules, and
discusses issues related to Unicode strings.
Regular expressions let you specify pattern strings and allow
searches and substitutions. Regular expressions are not easy to
master, but they are a powerful tool for processing text. Python
offers rich regular expression functionality through the built-in
re module, as documented in this chapter.
Methods of String Objects
Plain
and Unicode strings are immutable sequences, as covered in Chapter 4. All immutable-sequence operations
(repetition, concatenation, indexing, slicing) apply to strings. A
string object s also supplies several
non-mutating methods, as documented in this section. Unless otherwise
noted, each method returns a plain string when
s is a plain string, or a Unicode string
when s is a Unicode string. Terms such as
letters, whitespace, and so on refer to the corresponding attributes
of the string module, covered later in this
chapter. See also the later section Section 9.2.1.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access