String manipulations are an integral part of any programming language. Python is no different. The makers of python have provided a rich collection of built-in string methods to suit almost any kind of string processing. With the help of these python in-built methods you can trim, extract a substring, format, count, etc almost any string.
Below we have listed built-in python methods for strings. By clicking on each string method you can see how they can be used with examples.
Below we have listed built-in python methods for strings. By clicking on each string method you can see how they can be used with examples.
casefold()
|
Python string method returns a casefold copy of string, used for caseless matching.
|
capitalize()
|
Python string method returns a copy of string with first character capitalised and remaining in lowercase.
|
center()
|
Python string method returns string centered in a provided width.
|
count()
|
Python string method returns the number of occurrences of a substring in a given string.
|
encode()
|
Python string method returns encoded version of the given string.
|
endswith()
|
Python string method returns True if a string ends with the given suffix.
|
expandtabs()
|
Python string method specifies the amount of space to be replaced with the “\t” symbol in the string.
|
find()
|
Python string method returns the lowest index of the substring if it is found in a given string.
|
format()
|
Python string method used for multiple substitutions and value formatting.
|
format_map()
|
Python string method used to return a dictionary key value.
|
index()
|
Python method searches an element in the list and returns its index.
|
isalnum()
|
Python string method checks if all the characters in a string is alphanumeric or not.
|
Python string built-in method used for string handling.
|
|
isascii()
|
Python string method returns all characters in the string are ASCII or not.
|
isdecimal()
|
Python string method checks if all characters in the string are decimal characters.
|
Python string method determines whether the given character is a digit.
|
|
isidentifier()
|
Python string method checks whether a string is a valid identifier.
|
islower()
|
Python string method checks characters in the string are lowercase or not.
|
isnumeric()
|
Python string method determines whether all the characters of the string are numeric characters or not.
|
isprintable()
|
Python string method checks if all characters in the string are printable or the string is empty.
|
isspace()
|
Python string method checks if there are only whitespace characters in the string.
|
istitle()
|
Python string method determines if the string is a title cased string
|
isupper()
|
Python string method checks the given string is either in uppercase, or not.
|
join()
|
Python string method returns a string in which the elements of a sequence have been joined.
|
ljust()
|
Returns the string left justified.
|
lower()
|
Returns returns the lowercased string.
|
lstrip()
|
Python string method returns a copy of the string with leading characters are removed.
|
maketrans()
|
This static method returns a translation table usable for translate().
|
partition()
|
This method is used for splitting the string.
|
replace()
|
replace method is used for string substitution.
|
rfind()
|
This python method returns the highest index of the substring if found in given string.
|
rindex()
|
Python method returns the highest index of the substring inside the string, if found.
|
rjust()
|
This method returns the string right justified.
|
rpartition()
|
This method is used for splitting the string.
|
rsplit()
|
Python string method returns a list of strings after breaking it in smaller ones.
|
rstrip()
|
Python string returns a copy of the string with trailing characters removed.
|
This method returns a list of strings after breaking the given string by the specified separator.
|
|
splitlines()
|
Python method splits the string based on the lines.
|
startswith()
|
Checks if string starts with the given prefix.
|
strip()
|
Python string method returns a string with both leading and trailing characters removed.
|
swapcase()
|
Python method converts all uppercase characters to lowercase and vice versa.
|
title()
|
Converts a given string to titlecased.
|
translate()
|
Returns the string where each character has been mapped through the given translation table.
|
upper()
|
Returns a string in uppercase.
|
zfill()
|
Python string method returns a copy of the string left filled with ASCII '0'.
|