Page 362 - Computer Science V2.0 Class 11
P. 362
str.capitalize() Returns a string that has the first letter >>> string_s1.capitalize()
of the first word in the original string Touchpad computer science
converted to uppercase, while the
remaining letters are converted to
lowercase.
str.strip() Returns a string formed from the >>>string_s2= " Touchpad
original string by removing the Computer Science "
whitespace characters (space, tab, >>>string_s2.strip()
linefeed, return, form feed, and vertical Touchpad Computer Science
tab) appearing at the beginning and
end of the string.
str.lstrip() Remove the whitespace only from the >>>string_s2= " Touchpad
beginning of the string Computer Science "
>>>string_s2.lstrip()
"Touchpad Computer Science "
str.rstrip() Remove the whitespace only from the >>>string_s2= " Touchpad
end of the string Computer Science "
>>>string_s2.rstrip()
" Touchpad Computer Science"
str.isupper() Tests whether the string comprises >>> string_s1= 'Touchpad
only uppercase characters. Computer Science'
>>> string_s1.isupper()
False
str.islower() Tests whether the string comprises >>> string_s1.islower()
only lowercase characters. False
str.isalpha() Tests whether a string comprises only >>>string_s2=
alphabets "TouchpadComputerScience"
>>>string_s2.isalpha()
True
str.isdigit() Tests whether a string comprises only >>>string_s2=
digits "TouchpadComputerScience"
>>>string_s2.isdigit()
False
str.isalnum() Tests whether a string contains only >>>string_s2=
alphabets and digits. "TouchpadComputerScience11"
>>>string_s2.isalnum()
True
str.isspace() Tests whether a string comprises only >>>string_s2=
whitespace characters. "TouchpadComputerScience11"
>>>string_s2.isspace()
False
str. Tests whether the string str starts >>> string_s1= 'Touchpad
startswith(subStr) with the string subStr, passed as a Computer Science'
parameter. >>>string_s1.startswith('To')
True
348 Touchpad Computer Science (Ver. 2.0)-XI

