Python String Operations
Let's review some useful Python string methods.
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:
Press + to interact
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:
Press + to interact
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 as the ...