Built-In String Functions

In this lesson, we'll take a look at some of the built-in functions offered by Python.

Python boasts a huge library of built-in functions.

And trust us when we say that there’s something for almost everyone.

Strings

Functions that are properties of a particular entity are known as methods. These methods can be accessed using the . operator. The string data type has several methods associated with it. Let’s look at some of them.

Search

An alternative for finding a substring using the in keyword is the find() method. It returns the first index at which a substring occurs in a string. If no instance of the substring is found, the method returns -1.

-1 is a conventional value that represents a None or failure in case the output was supposed to be positive.

For a string called a_string, find() can be used in the following way:

a_string.find(substring, start, end)
  • substring is what we are searching for.
  • start is the index from which we start searching in a_string.
  • end is the index where we stop our search in a_string.

start and end are optional.

Get hands-on with 1200+ tech skills courses.