Python String Functions

The Python String Library provides various string Functions, which allows us to perform required operations on the String data. In this section, let me show you the list of Python String Functions or methods and its functionality. You can use the Hyperlinks to find detailed information about each one of the Python String methods along with practical examples.

Python String Functions

Unlike List, Python string is immutable. So, we cannot perform adding, removing kinds of operations on this. However, one can perform a slice or concatenate using python string methods.

Apart from this, it has its own methods to convert it to uppercase and lowercase, splitting, joining, etc. The list of String methods in Python are

FunctionsDescription
capitalize()It converts the first character to Capitalize and following characters to Lowercase.
casefold()It returns the given sentence in Lowercase.
center()This method is to Justify the line to Center and fill the remaining width with default white spaces
count()It Counts how many times the substring occurs.
encode()Prints the encoded version of a string object
endswith()This Python string functiuon displays TRUE if the string ends with the specified substring
expandtabs()It returns a copy of the given one, where all the tab characters replaced with one or more spaces.
find()The index position of the first occurrence. Otherwise, it displays -1 if the specified one not found
format()Useful for formatting
format_map()This Python function Format the string.
index()It returns the index position of the first occurrence of a specified substring. It raises ValueError if the specified one not found.
isalnum()TRUE if it contains letters and numbers
isalpha()TRUE if it has at least one letter, and all the characters are Alphabetic
isdecimal()TRUE if it has at least one letter, and all the characters are Decimal
isdigit()This python string function display TRUE if the string has at least one letter, and all the letters are Digits
isidentifier()TRUE if it is a valid identifier. Otherwise, it returns false.
islower()TRUE if it has at least one letter, and all the characters are in Lowercase
isnumeric()It displays TRUE if it has at least one letter, and all the letters are Numeric
isprintable()This python string function returns TRUE if all the letters are Printable
isspace()It prints TRUE if the sentence contains only white spaces
istitle()Prints TRUE if it has at least one character, and it is a Title.
isupper()TRUE if the sentence has at least one letter, and all the characters are in Uppercase
join()Join (Concatenate) a list of substrings
ljust()Justify to the Left-hand side and fill the remaining width with default white spaces
lower()It converts the given String into Lowercase characters and returns a new.
lstrip()This python string functions removes the white spaces from the Left-hand side.
maketrans()It returns the transaction table. We can further use this transaction in translate() method.
partition()It partitions the given one at the first occurrence of the specified separator and returns a tuple with three arguments.
replace()This python string function searches for a specified word and replaces it with a new value.
rfind()It display the index position of the Last occurrence. It returns -1 if the specified one not found
rindex()It returns the index position of the Last occurrence. It raises ValueError if the specified Python string not found
rjust()Justify to the Right-hand side and fill the remaining width with default white spaces
rpartition()This python string functions partitions the given sentence using the specified separator and returns a tuple with three arguments.
rsplit()Split into a list of sentences based on the specified delimiter. It happens from right to left
rstrip()It removes the white spaces from the Right-hand side.
split()This python string functions is very useful to Split into a list of substrings based on the specified delimiter
splitlines()It prints a list of lines by breaking the given one at line boundaries.
startswith()TRUE if the sentence Starts with the specified substring
strip()It removes the white spaces from both ends. Performs both lstrip() and rstrip()
swapcase()Converts the Lowercase letters into Uppercase. And Uppercase letters into Lowercase
title()It converts the first character in each word to Uppercase and following characters to Lowercase
translate()Prints a Copy of the given one in which each character mapped with the transaction table.
upper()This Python string function converts into Uppercase letters and returns a new one.
zfill()Prints a copy filled with ASCII ‘0’ digits on the left-hand side of the sentence to make a length to the specified width.