Search⌘ K
AI Features

Python String Operations

Explore fundamental Python string operations crucial for NLP tasks, including indexing, slicing, and case manipulation. Understand how to work with strings effectively as a foundation before advancing with spaCy's natural language processing tools.

We'll cover the following...

Reviewing some useful string operations

In Python, the text is represented by strings, objects of the str class. Strings are immutable sequences of characters. Creating a string object is easy—we enclose the text in quotation marks:

Python 3.5
word = 'Hello World'

Now the word variable contains the string Hello World. As we mentioned, strings are sequences of characters, so we can ask for the first item of the sequence:

Python 3.5
word = 'Hello World'
print(word[0])

Always remember to use parentheses with print, since we are coding in Python 3.x. We can similarly access other indices, as long ...