String Functions in Python

String Functions in Python

String functions in Python are used to manipulate them and retrieve some information from it like a range of characters. A number of methods and functions for strings are there and they have been listed below in the form of a table.

 

String Functions in Python Description
capitalize() This method converts first character of the specified string object into uppercase and rest of the characters into lowercase.
casefold() This method converts the specified string object into lowercase.
center() This method returns a centered string.
count() This method returns the number of times a character or a string occurs in the specified string object.
encode() This method returns an encoded version of the specified string object.
endswith() This method returns True if the specified string object ends with a specific string.
expandtabs() This method is used to set the tab-size of the specified string object.
find() This method is used to search the specified string object for a string and returns the position where it is found (if found).
format() This method returns a formatted string object.
format_map() This method returns a formatted string object.
index() This method returns the index number of the first occurrence of the character sequence in the specified string object.
isalnum() This method returns True if all the characters of the specified string object are alphanumeric(characters and digits), if not, returns False.
isalpha() This method returns True if all the characters of the specified string object are alphabet, if not, returns False.
isdecimal() This method returns True if all the characters of the specified string object are decimals, if not, returns False.
isdigit() This method returns True if all the characters of the specified string object are digits, if not, returns False.
isidentifier() This method returns True if the specified string object is an identifier, otherwise, returns False.
islower() This method returns True if all the characters of the specified string object are in lowercase, if not, returns False.
isnumeric() This method returns True if all the characters of the specified string object are numeric, if not, returns False.
isprintable() This method returns True if all the characters of the specified string object are printable, if not, returns False.
isspace() This method returns True if all the characters of the specified string object are whitespaces, if not, returns False.
istitle() This method returns True if the characters of the specified string object are in title format, if not, returns False.
isupper() This method returns True if all the characters of the specified string object are in uppercase, if not, returns False.
join() This method is used join elements of an iterable to the end of the specified string object.
ljust() This method returns a left-justified version of the specified string object.
lower() This method converts all characters of the specified string object into lowercase.
lstrip() This method returns a left-trim version of the specified string object.
maketrans() This method returns a mapping table that can be used in transitions.
partition() This method returns a tuple where the specified string object is parted into three parts.
replace() This method returns a modifications of the specified string object where the modification being the substitution of character with the other.
rfind() This method returns the position of a string found in the specified string object from the right, thus giving the position of the last occurrence.
rindex() This method returns the position of a string found in the specified string object from the right, thus giving the position of the last occurrence.
rjust() This method returns a right-justified version of the specified string object.
rpartition() This method returns a tuple where the specified string object is parted into three parts.
rsplit() This method splits the specified string object at the specified separator and returns a list.
rstrip() This method returns a right-trim version of the specified string object.
split() This method splits the specified string object at the specified separator and returns a list.
splitlines() This method splits the specified string object at line breaks and returns a list.
startswith() This method returns True if the specified string object starts with a specific string.
strip() This method returns s trimmed version of the specified string object.
swapcase() This method converts lowercase characters into uppercase characters and uppercase characters into lowercase of the specified string object.
title() This method converts the specified string object into a title format.
translate() This method returns a translated version of the specified string object.
upper() This method converts all characters of the specified string object into uppercase.
zfill() This method is used to fill the specified string object with a certain number of 0 values in the beginning.
len() This method returns total number of characters that make up the specified string object.
Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *