Sitemap

Python String Methods Explained with Examples

5 min readAug 22, 2026

--

To apply a string method on a string.

Syntax: string.methodname()

Here are the string methods

  1. upper(): It is a string method in python it will convert all the lower case characters into uppercase and rest of characters remains same. It returns a new string.
Press enter or click to view image in full size

2. lower(): It is a string method in python it will convert all the characters into lowercase and rest of characters remains same. It returns a new string.

3. swapcase(): It is a string method in python it will convert lowercase characters into uppercase and uppercase characters into lowercase. It returns a new string.

4. capitalize(): It is a string method in python,which will convert the first character into upper if it is a lowercase character rest of characters will be same. It returns a new string.

Press enter or click to view image in full size

5. title(): It is a string method in python, which will convert the first character of a word into uppercase and rest of will be in lowercase. It returns a new string.

Press enter or click to view image in full size

6. count(): It is a string method in python by using count we can count the number of times a substring is present inside a string. Count is always written an integer value.

Press enter or click to view image in full size

count supports index, In this we use starting index and ending index. But in python it follows left to right only.

7. replace(): It is a string method in python it will replace a substring with another substring. It returns a new string. we can also control the limit.

Press enter or click to view image in full size

8. index(): It is a string method in python, it is used to return the location of a substring occurring in the first occurrence of a string. It also supports starting and ending index values to specify the range in which Python should search for the substring.

Press enter or click to view image in full size

9. rindex(): It is a string method in python, it is used to return the location of a substring occurring in the first occurrence of a string from right side.But index count starts from left to right only.

Get Vedasaraswathit’s stories in your inbox

Join Medium for free to get updates from this writer.

It also supports start and end index values to specify the range in which Python should search.

Press enter or click to view image in full size

10. find(): It is a string method in python that is used to return the index of the first occurrence of a specified substring in a string.

It works similarly to the index() method. However, there is one important difference: if the substring is not found, find()returns -1 instead of raising an error.

Press enter or click to view image in full size

11. rfind(): It is a string method in python that is used to return the index of the first occurrence of a specified substring in a string from right to left. But index count starts from left to right only.

Press enter or click to view image in full size

12. strip(): It is a string method in python which will remove a characters/elements from the starting and ending of a string. It returns a new string.

Press enter or click to view image in full size

13. lstrip(): It is a string method in python which will remove a characters/elements from the starting of a string. It returns a new string.

Press enter or click to view image in full size

14. rstrip(): It is a string method in python which will remove a characters/elements from the ending of a string. It returns a new string.

Press enter or click to view image in full size

15. spilt(): It is a string method in python which will split entire string into substring. Based on condition which we want split.

Press enter or click to view image in full size

16. rsplit(): It is a string method in python which will split entire string into substring, from right to left.

Press enter or click to view image in full size

17. partition(): It is a string method in python , it is same as split which will always split on substring.But here it follows a rule

i.e.,(“before split”, “split”, “after split”)

Press enter or click to view image in full size

18. rpartition(): It is a string method in python , it is same as split which will always split on substring, from right to left.

Press enter or click to view image in full size

--

--