+

Python string functions

Python has built-in functions for almost every string operation. To keep things simple, they are classified based on the frequency of their use as well as their operations.



Classification of string functions Python

  • Core Functions
  • Extended Functions
  • Miscellaneous (these functions are not specifically intended for strings, but they can be used to process strings)

Basic string functions

< td> Checks if all characters are numbers, then returns True < td> partition ()
capitalize () Converts the first character of a string to uppercase str_name.capitalize ()
casefold () It converts any string to lowercase regardless of case str_name. casefold ()
center () Used to center the line str_name.center (length, character)
count () To count the number of times a specific value appears on a line. str_name.count (value, start, end )
endswith () Checks , whether the string ends with the specified value, then returns True str_name.endswith (value, start, end)
find () Used to determine if the specified value is in a string str_name.find (value, start, end)
index () It is used to find the first occurrence of a specified value in a string str_name.index (value, start, end)
isalnum () Checks if all characters are alphanumeric, then returns True str_name.isalnum ()
isalpha () Checks if all characters are alphabetic (az), then returns True str_name.isalpha ()
isdecimal () Checks if all characters are decimal (0-9), then returns True str_name.isdecimal ()
isdigit () str_name.isdigit () < / td>
islower () Checks if all characters are lowercase, then returns True str_name.islower ()
isnumeric () Checks if all characters are numeric (0-9), then returns True str_name.isnumeric () < / td>
isspace () Checks if all characters are spaces, then returns True str_name.isspace ()
isupper () Checks if all characters are uppercase, then returns True str_name.isupper ()
lower () Used to convert all characters to lowercase str_name.lower ()
Used to split a string into a tuple of three elements. str_name.partition (value)
replace () Used to replace the specified word or phrase with another word or phrase in a string. str_name.replace (old value, new value no, count)
split () Used to split a string into a list str_name.split (separator, maxsplit) < / td>
splitlines () Used to split a line and compose a list. Splits on a line break. str_name.splitlines (keeplinebreaks)
startswith () Checks if a line starts with a specified value , then returns True str_name.startswith (value, start, end)
strip () Used to strip characters, specified in the argument, both ends str_name.strip (characters)
swapcase () Used to replace an uppercase string to lowercase or vice versa. str_name.swapcase ()
title () Converts the initial letter of each word to uppercase str_name.title ()
upper () It is used to convert all characters in a string to uppercase str_name.upper ()

Python Advanced String Functions

< tr>
encode ( ) Used to return encoded strings str_name.encode (co encoding = encoding, errors = errors)
expandtabs () To set or fix tab spaces between characters or alphabets str_name.expandtabs (tab size)
format () < / td> Replaces the variable name written in {} with the value at runtime str_name.format (value1, value2 & # 8230;)
format_map () To format the given string and return str_name.format_map (display)
isidentifier () Checks if characters are alphanumeric (az) and (0-9) or underscore (_) and returns True str_name.isidentifier ()
isprintable () Checks if all characters are printable, then returns True str_name.isprintable ()
istitle () Checks if all leading characters of words are in upper re gistre, then returns True str_name.istitle ()
join () Takes words as repeated and concatenates them into a string str_name.join (iterable)
ljust () Returns a left-aligned string with a minimum value specified as width str_name.ljust (length, character)
lstrip () Remove characters from the left margin based on the given argument str_name.lstrip (characters)
maketrans () Creates a mapped table used for translations. str_name.maketrans (x, y, z)
rsplit () Used to split the string from the right end str_name. rsplit (separator, maxsplit)
rfind () Searches for the specified value and finds the position of its last value. str_name.rfind (value, start, end)
rindex () Searches for the specified value and finds its position last value. str_name.rindex (value, start, end)
rjust () Returns a right-aligned string with a minimum value specified as width str_name.rjust (length, character)
rpartition () Searches for the last occurrence of the specified lines and breaks the string into a tuple of three elements. str_name.rpartition (value)
rstrip () Strips out characters from right end based on given argument str_name.rstrip (characters)
translate () Used to get a translated string str_name.translate (table)
zfill () It returns a new string with 0s appended to the left of the string. str_name.zfill (len)

Miscellaneous



Get Solution for free from DataCamp guru
ascii () It returns a string containing the printable object and ignores non-ASCII values, on line ascii (object)
bool () It returns a boolean value, that is, True or False for an object. bool (value)
bytearray () It returns an object containing an array of bytes provided via input bytearray (source, encoding, errors)
bytes () It returns a byte object that cannot be changed and is a sequence of integers numbers in the range from 0 to 255. bytes (source, encoding, errors)
enumerate () It is used for add a counter to an iterable and then return its value enumerate (iteration, start = 0)
float () Returns a floating point number from the given argument. float (argument)
hash () Returns the hash value of the object if applicable. hash (object)
id () It returns specific identification of an object, which is a unique integer. id (object)
int () It returns an integer object from given input and the base of the returned object will always be 10 int (x = 0, base = 10)
len () Returns the length of the sequence, i.e. the number of elements in the object. len (sequence)
map () It is used to apply a given function to each element of the iteration , which can be a tuple, list, etc., and also returns a list containing the resulting values. map (function, iteration, & # 8230;)
ord () It takes a single Unicode character string argument and returns its Unicode respect point ord (character)
print () It prints the provided object to any output device print (object (s), separator = separator, end = end, file = file, flush = flush )
slice () It creates an object that is a set of indices given by its range (start, stop, step). slice (start, stop, step)
type () Returns the type of the object type (object) type (name, base, dict)