String methods & built in functions
Method Result Example
len() Returns the length of the string r=len(a)
will be 4
[Link]() To capitalize the first character of the r=[Link]()
string/sentence and rest of it is in lower will be “Comp”
case
[Link]() Will return title case string r=[Link]()
where first letter of each word is in will be
upper case. My Comp
[Link]() Will return string in upper case r=[Link]()
will be “COMP”
[Link]() Will return string in lower case r=[Link]()
will be “comp”
will return the total count of a given
[Link]() element in a string r=[Link](‘o’)
will be 1
To find the starting index value of r=[Link] (‘m’)
[Link](sub) the substring position(starts from will be 2
0 index)
Returns the string with replaced r=[Link](‘my’,’yo
[Link]() sub strings ur’) will be
‘your comp’
r=[Link](‘om’)
[Link]() Returns index position of substring will be 1
String consists of only alphanumeric r=[Link]()
[Link]() characters (no symbols) returns True
returns True if String consists of r=[Link]()
[Link]() only alphabetic characters (no returns True
symbols)
[Link]() returns True if String’s alphabetic r=[Link]()
characters are all lower case returns True
[Link]() returns True if String consists of only r=[Link]()
numeric characters returns True
[Link]() returns True if String consists of only r=[Link]()
whitespace characters returns True
[Link]() returns True if String’s alphabetic r= [Link]()
characters are all upper case returns false
b=‘**comp’;
[Link](char) Returns a copy of the string with r=[Link](‘*’)
[Link](char) leading/trailing characters/spaces will be
removed ‘comp’
Removes specific character/spaces b=‘@@comp@@’;
[Link](char) from leading and trailing position r=[Link](‘@’)
will be
‘comp’
b=‘my comp’;
r=[Link]() will be
[Link]() Returns list of strings as splitted
[‘my’,‘comp’]
a=('jan', 'feb','mar')
b=‟&”
[Link] () Returns a string in which the string [Link](b)
elements have been joined by a 'jan&feb&mar'
separator.
partition(sep) The function partitions the strings at the a='The Green
first occurrence of separator, and returns Revolution'
the strings partition in three parts i.e. [Link]('Rev')
before the separator, the separator itself, ('The Green ', 'Rev',
and the part after the separator.(in form 'olution')
of a tuple).
[Link]('pe')
If the separator is not found, returns the ('The Green
string itself, followed by two empty Revolution', '', '')
strings