Wednesday, 16 January 2013

String Handling


String Handling

There are only a few applications which do not handle textual data
at all. In some cases you are not interested in text as such, but you
need to convert textual input to a format which is easy to handle
programmatically, for instance to lists or integers. Finally, when your
application has processed the data, it is often printed out in textual form,
so the application must convert internal data structures back to text.
Luckily, all this is straightforward in Python. In this section we introduce
basic operations on strings, which are used by many examples in this
book. Section 4.4, which introduces you to the SMS inbox, requires some
power tools for string handling.
In Python, strings are objects too. In effect, this means that all
string-related functions are available automatically without any imports,
but you need to remember to use the dot notation, for example
txt.find("is"), when calling the string functions. Note that it is
not possible to modify a string after creation. All string operations return
a new string and leave the original string intact.

No comments:

Post a Comment