November 2001
Beginner
320 pages
5h 53m
English
Python supports the basic text extraction from strings supported by the Perl substr() function using slices on a string, since strings are just another type of sequence. For the other functions traditionally supported through internal functions such as split() and chomp() we need to use the string module. We'll look in detail at the specifics later, but a quick list of the compatible functions are shown in Table 10.1.
| Perl function | Python equivalent |
|---|---|
| substr(text, offset) | text[offset:len] |
| index(text, substr, start) | string.index(text, substr, start) |
| rindex(text, substr, start) | string.index(text, substr, start) |
| split(expr, text, max) | string.split(text, expr, max) |
| join(expr, ... |