© Joey Bernard 2016

Joey Bernard, Python Recipes Handbook, 10.1007/978-1-4842-0241-8_1

1. Strings and Texts

Joey Bernard

(1)Fredericton, New Brunswick, Canada

Since the earliest days of computing, data used in computations was stored in basic text files. Anyone who has written shell scripts knows all too well that Unix systems and their utilities are built around the assumption that processing text will be much of the work of the program. Python is no different; it provides several programming elements to help with basic text processing tasks.

To begin, let’s note how Python stores strings. Strings are immutable lists, so they cannot be changed. Any change to a string’s contents requires making copies to new locations in memory. You must always keep ...

Get Python Recipes Handbook: A Problem-Solution Approach 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.