Strings
1.

What will be the output of above Python code?

str1="6/4"

print("str1")
A.  

1

B.  

6/4

C.  

1.5

D.  

str1

2.

 Which of the following will result in an error?

str1="python"
A.  

print(str1[2])

B.  

str1[1]="x"

C.  

print(str1[0:9])

D.  

Both (b) and (c)

3.

Which of the following is False?

A.  

String is immutable.

B.  

capitalize() function in string is used to return a string by converting the whole given string into uppercase.

C.  

lower() function in string is used to return a string by converting the whole given string into lowercase.

D.  

None of these.

4.

What will be the output of below Python code?

str1="Information"

print(str1[2:8])
A.  

format

B.  

formatio

C.  

orma

D.  

ormat

5.

What will be the output of below Python code?

str1="Aplication"

str2=str1.replace('a','A')

print(str2)
A.  

application

B.  

Application

C.  

ApplicAtion

D.  

applicAtion

6.

What will be the output of below Python code?

str1="poWer"

str1.upper()

print(str1)
A.  

POWER

B.  

Power

C.  

power

D.  

poWer

7.

What will the below Python code will return?

If str1="save paper,save plants"

str1.find("save")
A.  

It returns the first index position of the first occurance of "save" in the given string str1.

B.  

It returns the last index position of the last occurance of "save" in the given string str1.

C.  

It returns the last index position of the first occurance of "save" in the given string str1.

D.  

It returns the first index position of the first occurance of "save" in the given string str1.

8.

What will the below Python code will return?

list1=[0,2,5,1]

str1="7"

for i in list1:

	str1=str1+i

print(str1)
A.  

70251

B.  

7

C.  

15

D.  

Error

9.

Which of the following will give "Simon" as output?

If str1="John,Simon,Aryan"
A.  

print(str1[-7:-12])

B.  

print(str1[-11:-7])

C.  

print(str1[-11:-6])

D.  

print(str1[-7:-11])

10.

What will following Python code return?

str1="Stack of books"
print(len(str1))
A.  

13

B.  

14

C.  

15

D.  

16