Q. 1

To add an element to a list which of the following expression is correct ?

Options:

Q. 2

What is the output of the following code ?

>>> s = [23, 24, 26, 56, 78]
>>> s.insert(3, 12)
>>> s

 

Options:

Explanation

Correct answer is : B

s.insert(3, 12) will insert 12 at index 3. So the result will be [23, 24, 26, 12, 56, 78]

Discuss It

Q. 3

What is the output of the following code ?

>>> s = [34, 56, 78, 23, 67, 23, 42]
>>> s.count(23)

 

Options:

Explanation

Correct answer is : A

s.count()     counts number times an element present inside the list

Discuss It

Q. 4

What is the output of the following code ?

>>> s1 = [16, 21, 72, 31, 91, 6, 12]
>>> s2 = s1.sort()
>>> s1, s2

 

Options:

Explanation

Correct answer is : C

s1.sort() sorts elements of the list in place, but does not return anything means returns None

so s1 will be [6, 12, 16, 21, 31, 72, 91].and s2 will be None

Discuss It

Q. 5

What is the output of the following code ?

>>> s1 = [11, 123, 36, 45, 34, 45, 67]
>>> s1.index(45)

 

Options:

Explanation

Correct answer is : D

s1.index(45) gives the index of element 45 in s1 which is 3 

Discuss It

Q. 6

What is the output of the following code ?

>>> s = ['python2' , 'python3', 'java8', 'perl5', 'java9']
>>> s.clear(), s.index('python3')

 

Options:

Explanation

Correct answer is : D

s.clear() - removes all elements from the list , so s.index('python3') will raise a ValueError as follows.

>>> s = ['python2' , 'python3', 'java8', 'perl5', 'java9']
>>> s.clear(), s.index('python3')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: 'python3' is not in list
>>>

 

Discuss It

Q. 7

What is the output of the following code ? 

>>> s = [67, 23, 34, 23]
>>> s.remove(23)
>>> s

 

Options:

Explanation

Correct answer is : A

s.remove(23) removes 23 only once from the list

Discuss It

Q. 8

What is the output of the following code ?

>>> s = [45 ,78, 25]
>>> s.extend((56, ))
>>> s

 

Options:

Explanation

Correct answer is : C

s.extend() takes any iterable and adds to the list.

So the result will be [45, 78, 25, 56]

Discuss It

Q. 9

>>> s = [24, 68, 33, 12, 92, 38]
>>> s[3] + s.pop()

 

Options:

Explanation

Correct answer is : A

s[3] will give 12 and s.pop() will give 38 . 

12 + 38 will be 50 

Discuss It

Q. 10

What is the output of the following code ?

>>> s = [19, 12, 87]
>>> s.append([56])
>>> s.extend([87, 12])
>>> s

 

Options:

Explanation

Correct answer is : C

s.append([56]) will add [56] which is a list to "s" , and s.extend([87, 12]) will add individual elements 87 and 12 to "s".

So the result will be [19, 12, 87, [56], 87, 12]

Discuss It
Submit Your Answers

Interview Questions

on
Data Types

Tutorial

on
Data Types

Programs

on
Data Types
Click any Link
to navigate to certain page easily
Write a line to us
Your Email
Title
Description