Python String Methods
gocourse.in Maintenance

We'll be back soon

Our CDN (cdn.gocourse.in) is currently unreachable. Some images, JavaScript, or CSS files may not load properly.

Estimated downtime: ~30 minutes

Python String Methods

Kishore V

Python String Methods

Python strings come with a rich collection of built-in methods that allow you to analyze, modify, format, and validate text efficiently.

Important Note: Strings in Python are immutable. This means every string method returns a new string and never alters the original one.

Commonly Used Python String Methods

Below is a categorized explanation of important string methods with clear examples.

Case Conversion Methods

capitalize()

Makes only the first character uppercase.

Python programming

lower() and upper()

Convert strings to lowercase or uppercase.

python PYTHON

swapcase()

Switches uppercase letters to lowercase and vice versa.

hELLO world

title()

Capitalizes the first letter of each word.

Welcome To Python

Searching & Counting Methods

count()

Counts how many times a substring appears.

2

find() and rfind()

Find the position of a substring. Returns -1 if not found.

6 13

index() and rindex()

Similar to find() but throws an error if not found.

2

Trimming & Alignment Methods

strip(), lstrip(), rstrip()

Remove unwanted spaces.

Python Python Python

center(), ljust(), rjust()

Align text within a given width.

--------Menu-------- Menu................ ................Menu

Joining & Splitting Methods

split() and rsplit()

Split text into a list based on a separator.

['Python', 'Java', 'C++']

join()

Join elements of a list into a single string.

2026-01-03

splitlines()

Split text at line breaks.

['Line1', 'Line2', 'Line3']

Validation & Checking Methods

isalnum(), isalpha(), isdigit()

Check content type (alphanumeric, alphabetical, or digits).

True True True

islower() and isupper()

Check text case.

True True

isspace() and isprintable()

Check for whitespace and printable characters.

True False

startswith() and endswith()

Check how a string begins or ends.

True True

Replacement & Translation Methods

replace()

Replace part of a string.

I like Python

partition() and rpartition()

Split into three parts around a separator.

('user', '@', 'example.com')

translate() and maketrans()

Replace multiple characters at once.

2d5c1t34n

Formatting & Padding

format() and format_map()

Insert values into strings.

Hello Suriya, welcome!

zfill()

Pad numbers with zeros.

00045
Our website uses cookies to enhance your experience. Learn More
Accept !