Python Programming
Python fundamentals to advanced for interviews
25 Questions 10 Topics Take Test
Advertisement
Showing 21–25 of 25 questions
Q.21 Hard Basics & Syntax
Consider the following code:
x = [1, 2, 3]
y = x[::-1]
print(y)
What will be the output?
A [1, 2, 3]
B [3, 2, 1]
C [3, 1, 2]
D Error
Correct Answer:  B. [3, 2, 1]
EXPLANATION

The slice notation [::-1] reverses the list. [1, 2, 3] reversed is [3, 2, 1].

Take Test
Q.22 Hard Basics & Syntax
Which of the following will raise an IndexError?
A lst = [1, 2, 3]; lst[2]
B lst = [1, 2, 3]; lst[3]
C lst = [1, 2, 3]; lst[-1]
D lst = [1, 2, 3]; lst[0]
Correct Answer:  B. lst = [1, 2, 3]; lst[3]
EXPLANATION

A list with 3 elements has valid indices 0, 1, 2. Index 3 is out of range and raises IndexError.

Take Test
Q.23 Hard Basics & Syntax
What will be the output of:
x = [1, 2, 3]
y = x
x.append(4)
print(y)
A [1, 2, 3]
B [1, 2, 3, 4]
C Error
D None
Correct Answer:  B. [1, 2, 3, 4]
EXPLANATION

y = x creates a reference to the same list, not a copy. When x is modified, y reflects the changes.

Take Test
Q.24 Hard Basics & Syntax
What is the output of: print(2 ** 3 ** 2)?
A 512
B 64
C 256
D 8
Correct Answer:  A. 512
EXPLANATION

The operator is right-associative. So 2 3 2 = 2 (3 2) = 2 9 = 512.

Take Test
Q.25 Hard Basics & Syntax
What will be the output of the following code?
x = [1, 2, 3]
x.append([4, 5])
print(len(x))
A 5
B 4
C 3
D Error
Correct Answer:  B. 4
EXPLANATION

append() adds the entire list [4, 5] as a single element. So x becomes [1, 2, 3, [4, 5]] with length 4.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips