Strings:-Built-in Functions

Python provides some following built-in methods to manipulate strings:-
(I). capitalize() :-
It returns the string with only its first character capitalized.
As:-
Untitled
(II). isdigit() :-
It returns True if the string contains only digits,False otherwise.
As:-
Untitled
(III).  isalnum() :-
 
If string contains alphanumric characters with atleast one character,it returns True.False otherwise.As:-
Untitled
(IV). isalpha() :-
It checks whether the string contains alphabetic characters only or not. Returns accordingly True & False. As:-
Untitled
(V). len():-
This is used to find the length of the string. As:-
Untitled
(VI). isupper() :-
this method checks if the string consists with uppercase letter or not.Returns value accordingly True or False. As:-
Untitled
                                          islower() also works as isupper but returns lower case.
(VII). lower() :-
It converts all the characters of string in lowercase form.As:-
Untitled
(VIII). upper() :-
It converts all the characters of string in uppercase form.As:-
Untitled
(IX).  max() :-
Using this you can find,maximum character of a string(max means which is having highest ASCII value) .
(X). min() :-
It is as max() but returns min character according to their ASCII value.
both can be used As:-Untitled
(XI). swapcase() :-
This function is used to swap the case.As:-
Untitled
(XII). replace() :-
This function is used to replace old copy of the string with new. There are three parameters named as old,new &  tim ( how many time you want to make changes) now the syntax for replace() will be str.replace(“old”, “new”, tim). but default(without tim) it will replace all occurrences.As:-
Untitled

(XIII). find() :-
It tells the the occurrence of a substring in a string.return index if found otherwise -1. This function required three parameters substr,beg & end (beg & end are values from where to where we have to find).By default beg is 0 and end is the length of the string.Now syntax is str.find(substr,beg,end) . As:-
Untitled
(XIV). index() :-
This is same as find but gives error when substring is not found.Syntax is also same as find index(substr,beg,end).
Untitledby default beg is set on 0 and end = len(str).

(XV). rfind() & rindex() :-
Both are same as find() and index() respectively  but difference is that it returns last index where the substr is found otherwise -1( in case of rfind() ) and error ( in case of rindex() ).
As:-
Untitled
(XVI). split() :-
This function works as a separator and makes list of all words.Two parameters are
required str and tim. tim(number of time).By default str is whitespace.As:-
Untitled
(XVII). join() :-
this method merge the string between the provided sequence .As shown here:-
Untitled
(XVIII). count() :-
This method tells us how many time substr occur in a string.Syntax is str.count(substr,beg,end). By default beg =0 , and end = len(str).As:-
Untitled

Leave a comment