Python Tutorial Python Advanced Python References Python Libraries

Python - String Methods



The Python has a number of methods and functions that are available for use with strings. These methods and functions are listed below in alphabetical order. For more details about any one of these, please visit its page.

String Methods & Functions

MethodsDescription
capitalize() Converts first character of first world into uppercase and rest into lowercase.
casefold() Converts string into lower case.
center() Returns a centered string.
count() Returns the number of times a specified value occurs in a string.
encode() Returns an encoded version of the string.
endswith() Returns true if the string ends with the specified value.
expandtabs() Sets the tab size of the string.
find() Searches the string for a specified value and returns the position of where it was found.
format() Formats specified values in a string.
format_map() Formats specified values in a string.
index() Returns the index number for first occurrence of specified character sequence in the string.
isalnum() Returns true when all characters of the string are alphanumeric, else returns false.
isalpha() Returns true when all characters of the string are alphabet, else returns false.
isdecimal() Returns true when all characters of the string are decimals, else returns false.
isdigit() Returns true when all characters of the string are digits, else returns false.
isidentifier() Returns true when the string is an identifier, else returns false.
islower() Returns true when all characters of the string are in lowercase, else returns false.
isnumeric() Returns true when all characters of the string are numeric, else returns false.
isprintable() Returns true when all characters of the string are printable, else returns false.
isspace() Returns true when all characters of the string are whitespaces, else returns false.
istitle() Returns true when the characters of the string is in title format, else returns false.
isupper() Returns true when all characters of the string are in uppercase, else returns false.
join() Joins the elements of an iterable to the end of the string.
ljust() Returns a left justified version of the string.
lower() Converts all characters of the string into lowercase.
lstrip() Returns a left trim version of the string.
maketrans() Returns a mapping table to be used in translations.
partition() Returns a tuple where the string is parted into three parts.
replace() Returns a string where a specified value is replaced with a specified value.
rfind() Searches the string for a specified value and returns the last position of where it was found.
rindex() Searches the string for a specified value and returns the last position of where it was found.
rjust() Returns a right justified version of the string.
rpartition() Returns a tuple where the string is parted into three parts.
rsplit() Splits the string at the specified separator, and returns a list.
rstrip() Returns a right trim version of the string.
split() Splits the string at the specified separator, and returns a list.
splitlines() Splits the string at line breaks and returns a list.
startswith() Returns true if the string starts with the specified value.
strip() Returns a trimmed version of the string.
swapcase() convert all lowercase characters into uppercase and uppercase characters into lowercase.
title() Converts all characters of the string in title format.
translate() Returns a translated version of the specified string.
upper() Converts all characters of the string into uppercase.
zfill() Fills the string with a specified number of 0 values at the beginning.
FunctionsDescription
len() Returns total number of characters in the string.