GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Python Tutorial
  • Data Types
  • Interview Questions
  • Examples
  • Quizzes
  • DSA Python
  • Data Science
  • NumPy
  • Pandas
  • Practice
  • Django
  • Flask
  • Introduction1 min read
  • Input & Output2 min read

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — Python String Methods - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • Python Tutorial
  • Data Types
  • Interview Questions
  • Examples
  • Quizzes
  • DSA Python
  • Data Science
  • NumPy
  • Pandas
  • Practice
  • Django
  • Flask

Python String Methods

Last Updated : 16 Jul, 2026

Python string methods are built-in functions that allow us to perform different operations on strings, such as changing letter case, searching text, replacing characters, splitting strings and checking string properties. Since strings are immutable in Python, these methods return a new string instead of modifying the original one.

lower()

Converts all uppercase characters in a string to lowercase.

Syntax: string_name.lower()

In the code below, we will convert a string to lowercase.

Python
text = "Hello PYTHON"
print(text.lower())

Output
hello python

upper()

Converts all lowercase characters in a string to uppercase.

Syntax: string_name.upper()

In the code below, we will convert a string to uppercase.

Python
text = "Hello Python"
print(text.upper())

Output
HELLO PYTHON

capitalize()

Converts the first character of the string to uppercase and the remaining characters to lowercase.

Syntax: string_name.capitalize()

In the code below, we will capitalize the first character of a string.

Python
text = "python programming"
print(text.capitalize())

Output
Python programming

replace()

Replaces all occurrences of a substring with another substring.

Syntax: string_name.replace(old, new)

In the code below, we will replace one word with another.

Python
text = "I like Java"
print(text.replace("Java", "Python"))

Output
I like Python

split()

Splits a string into a list using the specified separator.

Syntax: string_name.split(separator)

In the code below, we will split a sentence into words.

Python
text = "Python is easy"
print(text.split())

Output
['Python', 'is', 'easy']

join()

Joins elements of an iterable into a single string.

Syntax: separator.join(iterable)

In the code below, we will join a list of words using a hyphen.

Python
words = ["Python", "is", "easy"]
print("-".join(words))

Output
Python-is-easy

find()

Returns the index of the first occurrence of a substring. Returns -1 if the substring is not found.

Syntax: string_name.find(substring)

In the code below, we will find the position of a word.

Python
text = "Learn Python"
print(text.find("Python"))

Output
6

count()

Returns the number of times a substring appears in the string.

Syntax: string_name.count(substring)

In the code below, we will count the occurrences of a word.

Python
text = "apple apple mango"
print(text.count("apple"))

Output
2

strip()

Removes leading and trailing whitespace from a string.

Syntax: string_name.strip()

In the code below, we will remove extra spaces.

Python
text = "   Python   "
print(text.strip())

Output
Python

startswith()

Checks whether a string starts with the specified prefix.

Syntax: string_name.startswith(prefix)

In the code below, we will check whether the string starts with "Py".

Python
text = "Python"
print(text.startswith("Py"))

Output
True

More String Methods

The following built-in string methods are also available in Python:

MethodDescription
casefold()Converts the string to lowercase for case-insensitive comparisons.
center()Centers the string within the specified width.
encode()Encodes the string using the specified encoding.
endswith()Checks whether the string ends with the specified suffix.
expandtabs()Replaces tab characters with spaces.
format()Formats a string using the given values.
format_map()Formats a string using a dictionary.
index()Returns the index of a substring or raises an error if not found.
isalnum()Returns True if all characters are alphanumeric.
isalpha()Returns True if all characters are alphabetic.
isascii()Returns True if all characters are ASCII characters.
isdecimal()Returns True if all characters are decimal digits.
isdigit()Returns True if all characters are digits.
isidentifier()Checks whether the string is a valid Python identifier.
islower()Returns True if all alphabetic characters are lowercase.
isnumeric()Returns True if all characters are numeric.
isprintable()Returns True if all characters are printable.
isspace()Returns True if the string contains only whitespace.
istitle()Returns True if the string is in title case.
isupper()Returns True if all alphabetic characters are uppercase.
ljust()Left-aligns the string within the specified width.
lstrip()Removes leading characters or whitespace.
maketrans()Creates a translation table for translate().
partition()Splits the string into three parts at the first separator.
removeprefix()Removes the specified prefix if present.
removesuffix()Removes the specified suffix if present.
rfind()Returns the last occurrence of a substring or -1 if not found.
rindex()Returns the last occurrence of a substring or raises an error.
rjust()Right-aligns the string within the specified width.
rpartition()Splits the string into three parts at the last separator.
rsplit()Splits the string from the right.
rstrip()Removes trailing characters or whitespace.
splitlines()Splits the string into lines.
swapcase()Swaps uppercase and lowercase characters.
title()Converts the first letter of each word to uppercase.
translate()Replaces characters using a translation table.
zfill()Pads the string on the left with zeros until it reaches the specified width.

For more information about Strings, refer to Python String Tutorial.

Comment

Explore

    Python Fundamentals
    • Introduction1 min read
    • Input & Output2 min read
    • Variables4 min read
    • Operators4 min read
    • Keywords2 min read
    • Data Types4 min read
    • Conditional Statements3 min read
    • Loops3 min read
    • Functions4 min read
    Python Data Structures
    • String4 min read
    • List3 min read
    • Tuples3 min read
    • Dictionary3 min read
    • Set2 min read
    • Arrays5 min read
    Advanced Python
    • OOP Concepts3 min read
    • Exception Handling5 min read
    • File Handling4 min read
    • Python Database2 min read
    • MongoDB3 min read
    • MySQL7 min read
    • Packages4 min read
    • Modules3 min read
    • DSA Libraries5 min read
    • Python GUI2 min read
    Data Science with Python
    • Numpy3 min read
    • Pandas4 min read
    • Matplotlib3 min read
    • Seaborn3 min read
    • StatsModel2 min read
    • Model Building6 min read
    • TensorFlow2 min read
    • PyTorch5 min read
    Web Development with Python
    • Flask3 min read
    • Django5 min read
    • Django ORM4 min read
    • Jinja2 Templating5 min read
    • Django Templates5 min read
    • REST API3 min read
    • Build API with DRF4 min read
    Python Practice
    • Quiz1 min read
    • Practice Problems2 min read
    • Interview Q & A15+ min read
    Courses
    • Placement 360 Course2 min read
    • Data Science 360 Course2 min read
    • AI Engg Course2 min read
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.