TUTORIALS

String Functions in Python

Written By: Chaitra M
Created at: 28-June-2023 20:36:19
Modified at: 28-June-2023 20:36:39
MethodDescription
string.capitalize()Converts the first character to upper case
string.casefold()Converts string into lower case
string.swapcase()Swaps cases, lower case to upper case and vice versa
string.title()Converts the first character of each word to upper case in title format
string.count(value, start, end)Returns the number of times a specified value occured in a string
string.center(length, character)Returns a centered string
string.find(value, start, end)Searches the string for a specified value and returns the position of where it was found
string.encode(encoding, errors)Returns an encoded string format
string.endswith(value, start, end)Returns True if the string ends with the specified value
string.expandtabs(tabsize)Sets the tab size of the string
string.format(list of values)Formats specified values in a string
string.format_map()Formats specified values in a string
string.index(value, start, end)Searches the string for a specified value and returns the position of where it was found
string.isalnum()Returns True if all characters in the string are alphanumeric
string.isalpha()Returns True if all characters in the string are in the alphabet
string.isdecimal()Returns True if all characters in the string are decimals
string.isdigit()Returns True if all characters in the string are digits
string.isidentifier()Returns True if the string is an identifier
string.islower()Returns True if all characters in the string are lower case
string.isnumeric()Returns True if all characters in the string are numeric
string.isprintable()Returns True if all characters in the string are printable
string.isspace()Returns True if all characters in the string are whitespaces
string.istitle()Returns True if the string follows the rules of a title
string.isupper()Returns True if all characters in the string are upper case
string.join(iterable)Joins the elements of an iterable to the end of the string
string.ljust(length, character)Returns a left justified version of the string
string.lower()Converts a string into lower case
string.maketrans(x, y, z)Returns a translation table to be used in translations
string.partition(value)Returns a tuple where the string is parted into three parts
string.replace(oldvalue, newvalue, count)Returns a string where a specified value is replaced with a specified value
string.rfind(value, start, end)Searches the string for a specified value and returns the last position of where it was found
string.rindex(value, start, end)Searches the string for a specified value and returns the last position of where it was found
string.rjust(length, character)Returns a right justified version of the string
string.rpartition(value)Returns a tuple where the string is parted into three parts
string.strip(characters)Returns a trimmed string
string.lstrip(characters)Returns a left trim version of the string
string.rstrip(characters)Returns a right trim version of the string
string.rsplit(separator, maxsplit)Splits the string at the specified separator, and returns a list
string.split(separator, maxsplit) Splits the string at the specified separator, and returns a list
string.splitlines(keeplinebreaks)Splits the string at line breaks and returns a list
string.startswith(value, start, end)Returns true if the string starts with the specified value
string.translate(table)Returns a translated string
string.upper()Converts a string into upper case
string.zfill(len)Fills the string with a specified number of 0 values at the beginning
There are no likes. Be the first one to like
Likes: 0
Comments: 0