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 Python String Functions 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, a Python string has its own methods to convert it to uppercase and lowercase, splitting, joining, etc. The list of String Functions in Python are

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