Built-In String Functions
Explore some of the built-in string processing functions available in Python.
Python boasts a huge library of built-in functions. And trust us when we say that there’s something for almost everything. 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
Searching is important when working with strings, as it allows you to locate and manipulate specific substrings efficiently. An alternative for finding a substring using the in
keyword is the find()
method. Unlike in
, which returns True
if the substring exists and False
otherwise, find()
returns the first index at which a substring occurs in a string. If no instance of the substring is found, the method returns -1
. The -1
is a conventional value that represents a None
or failure in case the output was supposed to be positive.
For a string variable called a_string
, the find()
method can be used in the following way:
Get hands-on with 1400+ tech skills courses.