ZION AND ALWIN GROUP OF SCHOOLS
STRING METHODS AND FUNCTIONS
RETURNS
[Link] FUNCTION
DESCRIPTION VALUE EXAMPLE OUTPUT
. /METHOD
/NOT
returns length of the string s="Welcome_Python3.5"
ie) number of characters in print(len(s))
1 len() the string yes count=len(s) print(count)
returns copy of the string s="wElCoMe_PyThOn3.5"
with first character print([Link]())
2 capitalize() capitalized. yes s1=[Link]()
print(s1)
print(s)
returns number of times s="welcome to python3.5"
substring is present in the print([Link]('o'))
3 count() string yes o_count=[Link]('o')
print(o_count)
print(s)
returns the lowest index in the s="welcome to python3.5"
string where substring is print([Link]('o'))
4 find(sub,[start],[stop]) [Link] -1 if yes o_find=[Link]('o')
substring is not found. print(o_find)
print(s)
returns the lowest index where s="welcome to python3.5"
the substring is present. print([Link]('o'))
5 index(sub,[start],[stop]) Returns ValueError if yes o_find=[Link]('o')
substring is not present. print(o_find)
print(s)
RETURNS
[Link] FUNCTION
DESCRIPTION VALUE EXAMPLE OUTPUT
. /METHOD
/NOT
1. returns True if all the s1="welcomepython3"
characters in the string are s2=""
alphabets or digits. 2. s3="zps@[Link]"
returns False if string is print([Link]())
6 isalnum() empty. 3. yes print([Link]())
returns False if any one print([Link]())
character in the string is
special character(space is also
special character)
1. returns True if all the s1="welcomepython3"
characters in the string are s2=""
only digits. 2. s3="zips@[Link]"
returns False if string is s4="12345"
empty. 3. print([Link]())
7 isdigit() returns False if any one yes print([Link]())
character in the string is print([Link]())
special character or print([Link]())
alphabet(space is also special
character)
1. returns True if all the s1="welcomepython3"
characters in the string are s2=""
only alphabets. 2. s3="zips@[Link]"
returns False if string is s4="12345"
empty. 3. s5="ziongroup"
8 isalpha() returns False if any one yes print([Link]())
character in the string is print([Link]())
special character or print([Link]())
digit(space is also special print([Link]())
character) print([Link]())
RETURNS
[Link] FUNCTION
DESCRIPTION VALUE EXAMPLE OUTPUT
. /METHOD
/NOT
1. returns True if all the s1="WELCOMEHOME"
characters in the string are s2=""
only lower case alphabets or s3="zips@[Link]"
atleast one lowercase s4="12345"
character should be present. s5="ziongroup"
2. returns False s6="@#$%a"
if string is empty. s7="ziongrouP"
9 islower() 3. returns False if all the yes print([Link]())
character in the string are print([Link]())
special characters or digits or print([Link]())
uppercase(space is also print([Link]())
special character) print([Link]())
print([Link]())
print([Link]())
1. returns True if all the s1="WELCOMEHOME"
characters in the string are s2=""
only upper case alphabets or s3="ZIPS@[Link]"
atleast one upper case s4="12345"
character should be present. s5="ZIoN"
2. returns False s6="@#$%A"
10 isupper() if string is empty. yes print([Link]())
3. returns False if all the print([Link]())
character in the string are print([Link]())
special characters or digits or print([Link]())
lowercase(space is also print([Link]())
special character) print([Link]())
RETURNS
[Link] FUNCTION
DESCRIPTION VALUE EXAMPLE OUTPUT
. /METHOD
/NOT
1. returns True if all the s1="WELCOMEHOME"
characters in the string are s2=""
only digits. 2. s3="ZIPS123@[Link]"
returns False if string is s4="12345"
empty. 3. s5="@#$%90"
11 isdigit() returns False if the character yes print([Link]())
in the string are special print([Link]())
characters or alphabets(space print([Link]())
is also special character) print([Link]())
print([Link]())
1. returns a copy of the string s1="WELCOMEHOME"
converted to lower case. s2=""
2. ignores digits s3="ZIPS123@[Link]"
and special characters s4="12345"
s5="@#$%90"
12 lower() yes print([Link]())
print([Link]())
print([Link]())
print([Link]())
print([Link]())
RETURNS
[Link] FUNCTION
DESCRIPTION VALUE EXAMPLE OUTPUT
. /METHOD
/NOT
1. returns a copy of the string s1="WELcomeHOME"
converted to upper case. s2=""
2. ignores digits s3="zips@[Link]"
and special characters s4="12345"
s5="@#$%90"
print([Link]())
13 upper() yes print([Link]())
print([Link]())
print([Link]())
print([Link]())
returns copy of the string with s1=" WELcome HOME "
leading white spaces removed. s2=" "
s3="zips@[Link] "
print([Link](),end="$")
14 lstrip() yes print([Link](),end="$")
print([Link]())
returns copy of the string with s1=" WELcome HOME "
trailing white spaces removed. s2=" "
s3="zips@[Link] "
print([Link](),end="$")
15 rstrip() yes
print([Link](),end="$")
print([Link]())
RETURNS
[Link] FUNCTION
DESCRIPTION VALUE EXAMPLE OUTPUT
. /METHOD
/NOT
returns copy of the string with s1=" WELcome HOME "
trailing and leading white s2=" "
spaces removed. s3="zips@[Link] "
print([Link](),end="$")
16 strip() yes print([Link](),end="$")
print([Link](),end="$")
returns the copy of the string s1="red colour blue colour"
17 replace() with all the occurances of old yes print([Link]("colour","color"))
string replaced by new string print([Link](" ","@#"))
1. joins the string or character s1="red colour blue colour"
after each member of the l1=['red','blue','green']
sequence and returns it. l2=[23,'abi','pass']
2. If the sequence is tuple print('#'.join(s1))
18 join() or list all the members must yes print(' color '.join(l1))
be strings only. print(' color '.join(l2))
It splits the string and returns s1="red blue green"
as a list cotaining split string s2="z$i$p$s#a$m$p$s#a$i$p$s"
19 split() as member of the list. yes print([Link]())
print([Link]("#"))
RETURNS
[Link] FUNCTION
DESCRIPTION VALUE EXAMPLE OUTPUT
. /METHOD
/NOT
it splits the string only at the s1="red blue green"
first occurance of the s2="z$i$p$s##a$m$p$s#a$i$p$s"
separator and returns the tuple print([Link](" "))
20 partition() with three elements only.(part yes print([Link]("#"))
before separator,separatorand
part after separator)
returns True ifthe string starts s1="red blue green"
with substring or character print([Link](" "))
21 startswith() otherwise False. yes print([Link]("r"))
print([Link]("red"))
print([Link]("Red"))
returns True ifthe string ends s1="red blue green"
with substring or character print([Link](" "))
22 endswith() otherwise False. yes print([Link]("n"))
print([Link]("red"))
print([Link]("green"))
returns the title cased version s1="i love my India"
of the string ie) all the words s2="python java c++"
23 title() start with uppercase and yes print([Link]())
remaining characters in lower print([Link]())
case.
returns True if title cased s1="i love my India"
version of the string ie) all the s2="Python Java C++"
words start with uppercase print([Link]())
24 istitle() yes
and remaining characters in print([Link]())
lower case otherwise False.