String Methods

In this lesson, you will learn about the different methods of the string object in Python.

String methods introduction

A string is another type of object in Python. Most of the things you can do with strings involve using methods, and not functions. They have the form:

string.method(arguments)

There are a lot of string methods. Many of the most useful ones are listed in the appendix. Here, we discuss only a couple of the most useful and/or confusing string methods.

Splitting strings

For splitting strings in Python, we use the split() method. Over here, the string1.split(string2) command returns a list of the substrings of string1 that are separated by string2. The string2 argument is totally optional. If it is omitted, whitespace is used as the separator.

You can see this in the example below:

Get hands-on with 1200+ tech skills courses.