CHAPTER 4

image

Strings

String objects exist in practically every programming language. A string is simply a series of characters assigned to a variable. Python strings are immutable, which means that once created, they can not be changed. String assignments look like this:

s = 'Abcdefg'

Appending to Srings

Although Python strings are immutable, we can perform many operations on them, including appending other information to the string.>>> a = "This is a test"

>>> a = a + " of strings">>> a'This is a test of strings'

In this case, a copy of the string is made, the second string is appended to the copy, then the original is deleted and the new string ...

Get The Python Quick Syntax Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.