Skip to Content
Natural Language Processing with Python
book

Natural Language Processing with Python

by Steven Bird, Ewan Klein, Edward Loper
June 2009
Beginner to intermediate
504 pages
16h 27m
English
O'Reilly Media, Inc.
Content preview from Natural Language Processing with Python

Strings: Text Processing at the Lowest Level

It’s time to study a fundamental data type that we’ve been studiously avoiding so far. In earlier chapters we focused on a text as a list of words. We didn’t look too closely at words and how they are handled in the programming language. By using NLTK’s corpus interface we were able to ignore the files that these texts had come from. The contents of a word, and of a file, are represented by programming languages as a fundamental data type known as a string. In this section, we explore strings in detail, and show the connection between strings, words, texts, and files.

Basic Operations with Strings

Strings are specified using single quotes 1 or double quotes 2, as shown in the following code example. If a string contains a single quote, we must backslash-escape the quote 3 so Python knows a literal quote character is intended, or else put the string in double quotes 2. Otherwise, the quote inside the string 4 will be interpreted as a close quote, and the ...

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.
Start your free trial

You might also like

Natural Language Processing with Python and spaCy

Natural Language Processing with Python and spaCy

Yuli Vasiliev
Hands-On Natural Language Processing with Python

Hands-On Natural Language Processing with Python

Rajesh Arumugam, Rajalingappaa Shanmugamani

Publisher Resources

ISBN: 9780596803346Errata Page