Sitemap

STRING METHODS

3 min readAug 23, 2026

INTRODUCTION

Python strings are immutable, meaning that all built-in string methods return a new string or value rather than altering the original data.

The general syntax of a python string method is:

string.method()

Or ,if the string is stored in a variable:

variable.method()

1.upper( ):

upper() is a Python string method that converts all lowercase characters into uppercase character will be ignored return a new string.

2.lower( ):

lower() is a Python string method that converts all uppercase characters in a string into lowercase character and returns a new string.

3.swap case( ):

swap case() is a Python string method that converts uppercase letters to lowercase and lowercase letters to uppercase, and returns a new string.

• HELLO → hello •world → WORLD •123 → unchanged•@# →unchanged

4.capitalize( ):

capitalize() is a Python string method that converts the first character of a string to uppercase and all remaining characters to lowercase, and returns a new string.

The first character becomes uppercase; the remaining letters become lowercase.

5.title( ):

title() is a Python string method that converts the first character of each word in a string to uppercase and the remaining characters to lowercase.

6.count( ):

Get Krishnaveni’s stories in your inbox

Join Medium for free to get updates from this writer.

count() is a Python string method that count the number of times a substring is present inside a string and returns the count as an integer.

Press enter or click to view image in full size
count() does not change the original string; it returns the number of times.

7.replace( ):

replace() is a Python string method that replaces a substring with another substring and returns a new string.

Syntax:

string.replace(old, new)

8.index( ):

index( ) is a python string method that returns the index (position) the location of a substring occuring in the first occurance of a string.

syntax:

string.index(substring)
Python indexing starts from 0.

9.find( ):

find() is a Python string method that returns the index (position) of the first occurrence of a specified substring in a string. If the substring is not found, it returns -1.

find() and index() are similar, but when the text is not found, find() returns -1, while index() gives an error.

10.strip( ):-

strip() is a Python string method that removes the specified characters from the beginning and end of a string and returns a new string.

syntax:

string.strip(characters)
strip(“.”) removes the dots from the beginning and end.

11.lstrip( ):

lstrip() is a Python string method that removes leading (left-side) whitespace or specified characters from a string and returns a new string.

lstrip() removes characters only from the left side. It does not remove them from the right side.

12.rstrip( ):

rstrip() is a Python string method that removes trailing (right-side) whitespace or specified characters from a string and returns a new string.

rstrip() removes characters only from the right side.