The Python String Library provides various functions or methods, which allow 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 their functionality. You can use the Hyperlinks to find detailed information about each one of the String methods, along with practical examples.
Python String Functions
Unlike List, the string is immutable. So, we cannot perform adding or removing kinds of operations on this. However, one can perform a slice or concatenate using Python string methods or functions.
Apart from this, it has its own methods to convert it to uppercase and lowercase, splitting, joining, etc. The list of String functions or methods in Python are
Functions | Description |
---|---|
capitalize() | It converts the first character to Capitalize and the following characters to Lowercase. |
casefold() | It returns the given sentence in Lowercase. |
center() | It returns the index position of the first occurrence of a specified substring. It raises ValueError if the specified one is not found. |
count() | It Counts how many times the substring occurs. |
encode() | Prints the encoded version of a string object |
endswith() | This Python string function or method displays TRUE if the string ends with the specified substring |
expandtabs() | It returns a copy of the given one, where all the tab characters are 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() | It Formats the string. |
index() | Prints are TRUE if it has at least one character, and it is a Title. |
isalnum() | This Python string function or method returns 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() | It displays 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 or method returns TRUE if all the letters are Printable |
isspace() | It prints TRUE if the sentence contains only white spaces |
istitle() | This Python string function or method searches for a specified word and replaces it with a new value. |
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 one. |
lstrip() | It removes the white spaces from the Left-hand side. |
maketrans() | It returns the transaction table. We can further use this transaction in the 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 or method removes the white spaces from the left-hand side. |
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 text is not found |
rjust() | This Python string function or method justifies to the Right-hand side and fills the remaining width with default white spaces |
rpartition() | It 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 function or method 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() | Python string function or method converts the Lowercase letters into Uppercase. And Uppercase letters into Lowercase |
title() | It converts the first character in each word to Uppercase and the following characters to Lowercase |
translate() | Prints a Copy of the given one in which each character is mapped with the transaction table. |
upper() | It converts into Uppercase letters and returns a new one. |
zfill() | This Python string function prints a copy filled with ASCII ‘0’ digits on the left-hand side of the sentence to make a length to the specified width. |