This lesson will cover two essential Python types: strings and dictionaries.

Strings

One place where the Python language really shines is in the manipulation of strings. This section will cover some of Python's built-in string methods and formatting operations.

Such string manipulation patterns come up often in the context of data science work.

String syntax

You've already seen plenty of strings in examples during the previous lessons, but just to recap, strings in Python can be defined using either single or double quotations. They are functionally equivalent.

In [1]:

x = 'Pluto is a planet'
y = "Pluto is a planet"
x == y

Out[1]:

True

Double quotes are convenient if your string contains a single quote character (e.g. representing an apostrophe).

Similarly, it's easy to create a string that contains double-quotes if you wrap it in single quotes:

In [2]:

print("Pluto's a planet!")
print('My dog is named "Pluto"')

Pluto's a planet! My dog is named "Pluto"