Which of the following is true of Python lists all elements?

Python List MCQs

This section focuses on the "list" in Python. These Multiple Choice Questions (mcq) should be practiced to improve the Python skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1.Which of the following would give an error?

A. list1=[]
B. list1=[]*3
C. list1=[2,8,7]
D. None of the above

View Answer

Ans : D

Explanation: None of the above will result in error.


2.Which of the following is True regarding lists in Python?

A. Lists are immutable.
B. Size of the lists must be specified before its initialization
C. Elements of lists are stored in contagious memory location.
D. size(list1) command is used to find the size of lists.

View Answer

Ans : C

Explanation: Elements of lists are stored in contagious memory location is True regarding lists in Python.


3.What will be the output of below Python code?

list1=[8,0,9,5]
print(list1[::-1])

A. [5,9,0,8]
B. [8,0,9]
C. [8,0,9,5]
D. [0,9,5]

View Answer

Ans : A

Explanation: [5,9,0,8] will be the output of below Python code.


4.Which of the following will give output as [23,2,9,75] ?

If list1=[6,23,3,2,0,9,8,75]

A. print(list1[1:7:2])
B. print(list1[0:7:2])
C. print(list1[1:8:2])
D. print(list1[0:8:2])

View Answer

Ans : C

Explanation: print(list1[1:8:2]) of the following will give output as [23,2,9,75].


5.The marks of a student on 6 subjects are stored in a list, list1=[80,66,94,87,99,95]. How can the student’s average mark be calculated?

A. print(avg(list1))
B. print(sum(list1)/len(list1))
C. print(sum(list1)/sizeof(list1))
D. print(total(list1)/len(list1))

View Answer

Ans : B

Explanation: the student’s average mark be calculated through print(sum(list1)/len(list1)).


6.What will be the output of following Python code?

list1=["Python","Java","c","C","C++"]
print(min(list1))

A. c
B. C++
C. C
D. min function cannot be used on string elements

View Answer

Ans : C

Explanation: C will be the output of following Python code.


7.The elements of a list are arranged in descending order. Which of the following two will give same outputs?
i. print(list_name.sort())
ii. print(max(list_name))
iii. print(list_name.reverse())
iv. print(list_name[-1])

A. i, ii
B. i, iii
C. ii, iii
D. iii, iv

View Answer

Ans : B

Explanation: print(list_name.sort()) and print(list_name.reverse()) will give same outputs.


8. What will be the result after the execution of above Python code?

list1=[3,2,5,7,3,6]
list1.pop(3)
print(list1)

A. [3,2,5,3,6]
B. [2,5,7,3,6]
C. [2,5,7,6]
D. [3,2,5,7,3,6]

View Answer

Ans : A

Explanation: [3,2,5,3,6] will be the result after the execution of above Python code.


9.What will be the output of below Python code?

list1=[1,3,5,2,4,6,2]
list1.remove(2)
print(sum(list1))

A. 18
B. 19
C. 21
D. 22

View Answer

Ans : C

Explanation: 21 will be the result after the execution of above Python code.


10.What will be the output of below Python code?

list1=["tom","mary","simon"]
list1.insert(5,8)
print(list1)

A. ["tom", "mary", "simon", 5]
B. ["tom", "mary", "simon", 8]
C. [8, "tom", "mary", "simon"]
D. Error

View Answer

Ans : B

Explanation: ["tom", "mary", "simon", 8] will be the result after the execution of above Python code.





Discussion


* You must be logged in to add comment.

vanur swamy
it is very easy to understand

Q1. Which of the following statement will create list?

a. L1=list( )

b. L1=[1,2,3,4]

c. Both of the above

d. None of the above

Ans. c. Both of the above

Which of the following are true of Python lists? There is no conceptual limit size to a list O A given object may appear in a list more than once O A list may contain any type of object except another list

Video liên quan

Postingan terbaru

LIHAT SEMUA