Python Strings and their methods

With Code Implementation

Rohit Chaturvedi
2 min readMay 8, 2023

In Python, a string is a sequence of characters enclosed in quotation marks (either single quotes or double quotes). Strings are one of the basic data types in Python, and they can be manipulated using various built-in methods.

Here is an overview of some common string methods in Python:

  1. len() - returns the length of the string.
Fig 1.1 string len() method

2. lower() - returns a copy of the string in lowercase.

Fig 1.2 String lower() method

3. upper() - returns a copy of the string in uppercase.

Fig 1.3 String upper() method

4. strip() - removes any leading and trailing whitespace characters from the string.

Fig 1.4 String strip() method

5. replace() - replaces all occurrences of a specified substring in the string with another substring.

Fig 1.5 String replace() method

6. split() - splits the string into a list of substrings based on a specified delimiter.

Fig 1.6 String split() method

Summary :
These are just a few examples of the many string methods available in Python. By using these methods, you can manipulate and process strings in a variety of ways.

--

--