Home Subjects Python Programming Basics & Syntax

Python Programming
Basics & Syntax

Python fundamentals to advanced for interviews

20 Q 2 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 11–20 of 20
Topics in Python Programming
All Basics & Syntax 100 Data Types & Lists 19
Q.11 Hard Basics & Syntax
What will be the output of: print(any([False, False, True]))
A True
B False
C Error
D None
Correct Answer:  A. True
EXPLANATION

any() returns True if at least one element in the iterable is True.

Test
Q.12 Hard Basics & Syntax
Consider: x = [i**2 for i in range(4)]. What is x?
A [0, 1, 2, 3]
B [1, 4, 9, 16]
C [0, 1, 4, 9]
D [2, 4, 6, 8]
Correct Answer:  C. [0, 1, 4, 9]
EXPLANATION

List comprehension: i**2 for i in [0,1,2,3] produces [0, 1, 4, 9].

Test
Q.13 Hard Basics & Syntax
What will be the output of: d = {'a': 1, 'b': 2}; print(list(d.items()))
A [('a', 1), ('b', 2)]
B ['a', 'b']
C [1, 2]
D Error
Correct Answer:  A. [('a', 1), ('b', 2)]
EXPLANATION

dict.items() returns key-value pairs as tuples, converted to a list: [('a', 1), ('b', 2)].

Test
Q.14 Hard Basics & Syntax
Which of the following will raise a TypeError in Python?
A int('10')
B int(10.5)
C int('10.5')
D int(True)
Correct Answer:  C. int('10.5')
EXPLANATION

int('10.5') raises TypeError because '10.5' is a string representation of a float, not a valid integer string.

Test
Q.15 Hard Basics & Syntax
What will be the output of: print({1, 2, 3} | {3, 4, 5})?
A {1, 2, 3, 3, 4, 5}
B {1, 2, 3, 4, 5}
C {3}
D {1, 2, 4, 5}
Correct Answer:  B. {1, 2, 3, 4, 5}
EXPLANATION

The | operator performs set union, combining all unique elements from both sets. Result is {1, 2, 3, 4, 5}.

Test
Q.16 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].

Test
Q.17 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.

Test
Q.18 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.

Test
Q.19 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.

Test
Q.20 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.

Test
IGET
IGET AI
Online · Exam prep assistant
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