Page 370 - Computer Science V2.0 Class 11
P. 370
C. Fill in the blanks.
1. Python built-in type _____________enables us to deal with the strings in a Python program.
2. To include a single quote (') in a string enclosed in single quotes, it should be preceded by a _________ character.
3. Position of a character in a string is called its __________.
4. The built-in function that returns the number of characters in a string is __________.
5. Any value can be transformed to a string using the ___________ function.
6. A subsequence of characters of a string is called a _____________.
7. For any string s, s[:n] + s[n:] always yields ____________, irrespective of the value of n.
8. The ___________ method returns a string which has the first letter of every word of the original string converted to
uppercase.
D. Answer the following questions:
1. Consider the following assignment statement:
>>> tag = 'UnCover and COVer'
Using slicing, write an expression that would yield the substring 'COVer' from the string tag.
Ans. Any of the following expressions may be used to achieve this.
tag[-5:], tag[12:17], tag[12:]
2. Which arithmetic operator is used to concatenate two strings?
Ans. + operator
3. What will be the output produced on the execution of the following code?
def obfuscate(message):
length = len(message)
newStr = ''
for i in range(0, length):
if message[i].islower():
newStr = newStr + message[i].upper()
elif message[i].isdigit():
newStr = eval(message[i])
newStr = str(newStr)
else:
newStr = newStr + '#'
return newStr
print(obfuscate('Gr843?*$'))
Ans. 3###
4. What will be the output produced on the execution of the following code?
def obfuscate(message):
length = len(message)
newStr = ''
for i in range(0, length):
if message[i].islower():
newStr = newStr+message[i].upper()
elif message[i].isdigit():
str1 = eval(message[i])
newStr = newStr + str(str1)
else:
newStr = newStr + '#'
return newStr
print('Original string:', 'Hello123?*$')
356 Touchpad Computer Science (Ver. 2.0)-XI

