More on Strings
Python stores strings as an immutable sequence of characters—a jargon-filled way of saying that “it is a collection of characters that, once set, cannot be changed without creating a new string.” Sequences are important in Python. There are three primary types, of which strings are one, and they share some properties. Mutability makes a lot of sense when you learn about lists in the next section.
As you saw in the previous example, you can assign a value to strings in Python with just an equal sign, like this:
>>> mystring = 'hello';>>> myotherstring = "goodbye";>>> mystring'hello'>>> myotherstring;'goodbye'>>> test = "Are you really Bill O'Reilly?">>> test"Are you really Bill O'Reilly?"
The first example encapsulates the string ...
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