These all are the build-in function in python that can be used by any Python developers and learners, students, and other people too. These functions in python will help to improve the running time of any python program and save the time of any user to write the function to do small work like capitalize, split, find, and more.
Build-in String function in python
Python String Function:-
capitalize() function in python: -
capitalize() function in python used to convert the first letter of string into upper case.
Syntax : -
string.capitalize()
casefold() function in python: -
casefold() is the same as the lower() function both function are used to convert characters into lower case,but casefold() function is more stronger then lower() methos it means casefold() function can convert more characters into lower case.
Syntax : -
string.casefold()
center() function :-
center function in python used to align the string at the center using the specified character as the fill character.
Syntax : -
string.center(length, character)
Length is required because it is the length of returning the string.
The character used to fill the missing space on each side of the default string.
count() function :-
count() function in python programming helps to count the specified value appears in the string. You also have to tell about the start and endpoint for the count.
Syntax : -
string.count(value, start, end)
encode() function :-
count() function in python use to encode the string under the specified encoding if the encoding is not specified then UTF-8 will be used by default.
Syntax : -
string.encode(encoding=encoding, errors=errors)
'backslashreplace' - backslash uses when characters could not be encoded
'ignore' - it will ignore the characters that cannot be encoded
'namereplace' - a text explaining the character replace that character.
'strict' - Default, raises an error on failure
'replace' - question mark will replace the character
'xmlcharrefreplace' - an xml character will replace the character
endswith() in python :-
endswith() in python returns true if given string will end with the specified value, otherwise False.Syntax : -
string.endswith(value, start, end)
expandtabs() in python :-
expandtabs() method in python set the tab size to the specified number of whitespaces.Syntax : -
string.expandtabs(tabsize)
find() in python :-
find() function use to find the first occurrence for the given value. The find() function returns -1 if the value is not found.
Syntax : -
string.find(value, start, end)
index() in python:-
index() function is also used to find the first occurrence for the given value. The index() method raises an exception if the value is not found.
Syntax : -
string.index(value, start, end)
Python string isalnum() method:-
isalnum()method in python returns true if all the characters are
alphanumeric, it means letter (a-z) and numbers (0-9).
Syntax : -
string.isalnum()
Python string isalpha() function:-
isalpha()method in python returns true if all the given characters are alphabet letters (a-z).
Example for nonalphabet letters: - !#%&? etc.
Syntax : -
string.isalpha()
Python string isdecimal() function:-
isdecimal() method is slightly different from other "is function in python" this method returns true if all the given characters are decimals (0-9).
Syntax : -
string.isdecimal()
isdigit() function:-
isdigit()method in python returns true if all the given characters are digits, otherwise False.
Syntax : -
string.isdigit()
isidentifier() function:-
isidentifier() method gives the true if the string is a valid identifier, otherwise false, to check given string is valid identifier so string should contain alphanumeric letters (a-z) and (0-9), or underscores (_). A valid identifier can't be started with a number and space.
Syntax : -
string.isidentifier()
islower() function:-
This method returns true if all the string characters are in lower case otherwise false in python.
Syntax : -
string.islower()
isnumeric() function:-
isnumeric() method returns true if all the string characters are in are numeric (0-9), otherwise false in python.Syntax : -
string.isnumeric()
isprintable() function:-
isprintable() method returns true if all the string characters are in are printable, otherwise false in python.
Syntax : -
string.isprintable()
isspace() function:-
isspace() function in python programming returns true if all the string characters are whitespaces, otherwise false in python.
Syntax : -
string.isspace()
istitle() function:-
istitle() function follow the English language tradition because this function returns true if words in text start with upper case letter, AND end with the lower case letters, otherwise False.
Syntax : -
string.isspace()
join() function:-
join() function takes all the items to form an iterable and use to join them into one string
Syntax : -
string.join(iterable)
ljust() function:-
ljust() function in python is used to align the text on the left side with the help of the specified characters (space is the default) as the fill character.
Syntax : -
string.ljust(length, character)
lower() function:-
lower() function in python is used to return where all characters are lower case.Syntax : -
string.lower()
lstrip() function in python:-
lstrip() method is used to neglect any leading characters in python string-like default leading characters to remove.Syntax : -
string.lstrip(characters)
partition() function in python:-
partition() function in python searched for specified string and splits given string into a tuple which contains three elements.
The first element contains the part before the specified string and the second one contains the specified string and the last one contains the part after the string.
Syntax : -
string.partition(value)
replace() method in python:-
replace() function method replaces all specified phrase with another specified phrase.
Syntax : -
string.replace(oldvalue, newvalue, count)
rfind() in python :-
rfind() function used to find the last occurrence for the given value. The find() function returns -1 if the value is not found.
Syntax : -
string.rfind(value, start, end)
rindex() in python:-
rindex() function is also used to find the last occurrence for the given value. The index() method raises an exception if the value is not found.That's why rindex() is different from rfind() function in python.
Syntax : -
string.rindex(value, start, end)
rjust() in python:-
ljust() function in python is used to align the text on the right side with the help of the specified characters (space is the default) as the fill character.Syntax : -
string.rjust(length, character)
rpartition() function in python:-
rpartition() function in python searches last occurrence of a specified string and splits given string into a tuple which contains three elements.
The
the first element contains the part before the specified string and the
the second one contains the specified string and the last one contains the
the part after the string.
Syntax : -
string.rpartition(value)
rstrip() function in python:-
rstrip() method is used to neglect any trailing characters in python like space is a default trailing character to remove.Syntax : -
string.rstrip(characters)
split() method:-
As it name says split() function in python use to splits a string into a list.Syntax : -
string.split(separator, maxsplit)
startwith() in python :-
startwith() in python returns true if the given string will start with the specified value, otherwise False.Syntax : -
string.startswith(value, start, end)
swapcase() in python :-
startwith() in python returns the string where all the upper case letters are converted into the lower case and vice versa.
Syntax : -
string.swapcase()
zfill() in python :-
zfill() method in python add zeros at the starting of the string until it reaches the specified length.
Syntax : -
string.zfill(len)
These all are the function in python which is used to manipulate the strings in python programs.
0 comments:
Post a Comment