Sheet No.2+solution+summary
Sheet No.2+solution+summary
Sheet No.2+solution+summary
OR
4. a="python is a programming language"
print(len(a))
new=a[0:4]+a[-2:]
print(new)
5. b="languages"
print(b.index("g"))
OR print(b.find("g"))
print(b.find("f"))
OR print(b.index("f"))
The only difference is that find() method returns -1 if the substring is
not found, whereas index() throws an exception (ValueError: substring
not found).
6. str= "IT professionals may advance their careers by obtaining IT
certificates"
a=str.count("IT")
print(a)
b=str.replace("IT","ICT")
print(b)
c=str.islower()
print(c)
d=str.upper()
print(d,str.isupper())
e="\"IT\" professionals may advance their careers by obtaining \"IT\"
certificates"
print(e)
f=str.replace("a","--XIX--")
print(f)
Summry
%s : string, integer, float
%d : integer
upper()
is a built-in function, returns the uppercased string from the given
string. It converts all lowercase characters to uppercase.
lower()
is a built-in function, returns the lowercased string from the given
string. It converts all uppercase characters to lowercase.
len(string)
is a built-in function, returns the length of the string.
index()
is a built-in function,
• If substring exists inside the string, it returns the lowest index in the
string where substring is found.
• If substring doesn't exist inside the string, it raises
a ValueError exception.
parameters
a) sub: substring (ex. Character, word or sentence) to be searched in
the string.
b) start and end (optional)
start: starting index within the string where search starts.
end: ending index within the string where search ends.
find()
is a built-in function, returns the lowest index of the substring if it is
found in given string. If it is not found, then it returns -1.
count()
is a built-in function, returns the number of occurrences of a substring
in the given string.
str.count(sub, start, end)
replace()
is a built-in function, returns a copy of the string where all occurrences
of a substring are replaced with another substring.