Python Multiple Choice Questions & Answers (MCQs) focuses on “Matrix List Comprehension”.

Q 1. Which of the following matrices will throw an error in Python?
A. A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]

B. B = [[3, 3, 3]
[4, 4, 4]
[5, 5, 5]]

C. C = [(1, 2, 4),
(5, 6, 7),
(8, 9, 10)]

D. D = [2, 3, 4,
3, 3, 3,
4, 5, 6]

Show Answer Answer:-B. B = [[3, 3, 3] [4, 4, 4] [5, 5, 5]]
Explanation In matrix B will result in an error because in the absence of a comma at the end of each row, it behaves like three separate lists. The error thrown states that the list integers must be integers or slices, not tuples.

Q 2. What will be the output of the following Python code?

A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
A[1]

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

Show Answer Answer:-C. [4, 5, 6]
Explanation We can index the rows and columns using normal index operations. The statement A[1] represents the second row, that is, the middle row. Hence the output of the code will be: [4, 5, 6].

Q 3. Which of the following Python statements will result in the output: 6?

A = [[1, 2, 3],
     [4, 5, 6],
     [7, 8, 9]]

A. A[2][3]
B. A[2][1]
C. A[1][2]
D. A[3][2]

Show Answer Answer:-C. A[1][2]
Explanation The output that is required is 6, that is, row 2, item 3. This position is represented by the statement: A[1][2].

Q 4. What will be the output of the following Python code?

A = [[1, 2, 3],
      [4, 5, 6],
      [7, 8, 9]]
[A[row][1] for row in (0, 1, 2)]

A. [7, 8, 9]
B. [4, 5, 6]
C. [1, 4, 7]
D. [2, 5, 8]

Show Answer Answer:-D. [2, 5, 8]
Explanation To get a particular column as output, we can simple iterate across the rows and pull out the desired column, or iterate through positions in rows and index as we go. Hence the output of the code shown above is: [2, 5, 8].

Q 5. What will be the output of the following Python code?

A = [[1, 2, 3],
     [4, 5, 6],
     [7, 8, 9]]
[A[i][i] for i in range(len(A))]

A. [1, 5, 9]
B. [3, 5, 7]
C. [4, 5, 6]
D. [2, 5, 8]

Show Answer Answer:-A. [1, 5, 9]
Explanation We can also perform tasks like pulling out a diagonal. The expression shown above uses range to generate the list of offsets and the indices with the row and column the same, picking out A[0][0], then A[1][1] and so on. Hence the output of the code is: [1, 5, 9].

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

l=[[1, 2, 3], [4, 5, 6]]
for i in range(len(l)):
	for j in range(len(l[i])):
		l[i][j]+=10
l

A. [[1, 2, 3], [4, 5, 6]]
B. [[11, 12, 13], [14, 15, 16]
C. Error
D. No output

Show Answer Answer:-B. [[11, 12, 13], [14, 15, 16]
Explanation We use range twice if the shapes differ. Each element of list l is increased by 10. Hence the output is: [[11, 12, 13], [14, 15, 16]]

Q 7. What will be the output of the following Python code?

A = [[1, 2, 3],
     [4, 5, 6],
     [7, 8, 9]]
 
[[col + 10 for col in row] for row in A]

A. [[11, 12, 13], [14, 15, 16], [17, 18, 19]]
B. [11, 12, 13, 14, 15, 16, 17, 18, 19]
C. [11, 12, 13], [14, 15, 16], [17, 18, 19]
D. Error

Show Answer Answer:-A. [[11, 12, 13], [14, 15, 16], [17, 18, 19]]
Explanation The code shown above shows a list comprehension which adds 10 to each element of the matrix A and prints it row-wise. Hence the output of the code is: [[11, 12, 13], [14, 15, 16], [17, 18, 19]]

Q 8. What will be the output of the following Python code?

A = [[1, 2, 3],
     [4, 5, 6],
     [7, 8, 9]]
[A[i][len(A)-1-i] for i in range(len(A))]

A. [1, 5, 9]
B. [3, 5, 7]
C. [4, 5, 6]
D. [2, 5, 8]

Show Answer Answer:-B. [3, 5, 7]
Explanation This expression scales the common index to fetch A[0][2], A[1][1], etc. We assume the matrix has the same number of rows and columns.

Q 9. What will be the output of the following Python code?

A = [[1, 2, 3],
     [4, 5, 6],
     [7, 8, 9]]
B = [[3, 3, 3],
     [4, 4, 4],
     [5, 5, 5]]
[B[row][col]*A[row][col] for row in range(3) for col in range(3)]

A. [3, 6, 9, 16, 20, 24, 35, 40, 45]
B. 0
C. [0, 30, 60, 120, 160, 200, 300, 350, 400]
D. Error

Show Answer Answer:-A. [3, 6, 9, 16, 20, 24, 35, 40, 45]
Explanation In the code shown above, we have used list comprehension to combine values of multiple matrices. We have multiplied the elements of the matrix B with that of the matrix A, in the range(3). Hence the output of this code is: [3, 6, 9, 16, 20, 24, 35, 40, 45].

Q 10. What will be the output of the following Python code?

r = [11, 12, 13, 14, 15, 16, 17, 18, 19]
A = [[0, 10, 20],
               [30, 40, 50],
               [60, 70, 80]]
for row in A:
	for col in row:
		r.append(col+10)
r

A. [0, 10, 20, 30, 40, 50, 60, 70, 80]
B. [10, 20, 30, 40, 50, 60, 70, 80, 90]
C. [11, 12, 13, 14, 15, 16, 17, 18, 19]
D. [11, 12, 13, 14, 15, 16, 17, 18, 19, 10, 20, 30, 40, 50, 60, 70, 80, 90]

Show Answer Answer:-D. [11, 12, 13, 14, 15, 16, 17, 18, 19, 10, 20, 30, 40, 50, 60, 70, 80, 90]
Explanation The code shown above adds 10 to each element of the matrix and prints the output row-wise. Since the list l already contains some elements, the new elements are appended to it. Hence the output of this code is: [11, 12, 13, 14, 15, 16, 17, 18, 19, 10, 20, 30, 40, 50, 60, 70, 80, 90].

Q 11. What will be the output of the following Python code?

A = [[1, 2, 3],
     [4, 5, 6],
     [7, 8, 9]]
B = [[3, 3, 3],
     [4, 4, 4],
     [5, 5, 5]]
[[col1 * col2 for (col1, col2) in zip(row1, row2)] for (row1, row2) in zip(A, B)]

A. [0, 30, 60, 120, 160, 200, 300, 350, 400]
B. [[3, 6, 9], [16, 20, 24], [35, 40, 45]]
C. No output
D. Error

Show Answer Answer:-B. [[3, 6, 9], [16, 20, 24], [35, 40, 45]]
Explanation The list comprehension shown above results in the output: [[3, 6, 9], [16, 20, 24], [35, 40, 45]].

Q 12. What will be the output of the following Python code?

A = [[1, 2, 3],
     [4, 5, 6],
     [7, 8, 9]]
B = [[3, 3, 3],
     [4, 4, 4],
     [5, 5, 5]]
zip(A, B)

A. Address of the zip object
B. Address of the matrices A and B
C. [3, 6, 9, 16, 20, 24, 35, 40, 45]
D. No output

Show Answer Answer:-A. Address of the zip object
Explanation The output of the code shown above returns the address of the zip object. If we print it in the form of a list, we get: >>> list(zip(A, B)) [([1, 2, 3], [3, 3, 3]), ([4, 5, 6], [4, 4, 4]), ([7, 8, 9], [5, 5, 5])]

Leave a Reply

Your email address will not be published. Required fields are marked *

Author

quizsquestion@gmail.com

Related Posts

Top 100 UK GK Questions (Culture, Sport & Icons)

🎭 Culture (1–35) Q 1. What is the capital of the United Kingdom? Show Answer Answer:-London Q 2. What is the official...

Read out all

Current Affairs Quiz – May 2026

Q 1.Which state has been declared the country’s first paperless judiciary state? A. SikkimB. ManipurC. AssamD. Odisha Show Answer Answer:- A. Sikkim...

Read out all

Culture Sport & Icons Australia GK Question Top 100

Australia’s identity is a vibrant blend of the world’s oldest living culture, a deep-seated passion for sport, and a unique collection of...

Read out all

Current Affairs Quiz – March 2026

Q 1.Where was India–UK Conference on Green Hydrogen Standards and Safety Protocols held? A. New DelhiB. ChennaiC. HyderabadD. Bengaluru Show Answer Answer:-A....

Read out all

Python Questions and Answers – Exception Handling – 3

Python Multiple Choice Questions & Answers (MCQs) focuses on “Exception Handling – 3”. Q 1. What happens if the file is not...

Read out all

Important Events & History Canadian Multiple Choice Question

Q 1. In what year did Canadian Confederation take place? A. 1776 B. 1812 C. 1867 D. 1982 Show Answer Answer:-C. 1867...

Read out all

You cannot copy content of this page