Python Programming
Python fundamentals to advanced for interviews
25 Questions 10 Topics Take Test
Advertisement
Showing 11–20 of 25 questions
Q.11 Hard Basics & Syntax
Consider: *a, b = [1, 2, 3]. What is a?
A [1, 2]
B 1
C [1, 2, 3]
D Error
Correct Answer:  A. [1, 2]
EXPLANATION

The * operator in unpacking collects remaining elements. a gets [1, 2] and b gets 3.

Take Test
Q.12 Hard Basics & Syntax
What will be the result of: set([1, 2, 2, 3, 3, 3])?
A {1, 2, 2, 3, 3, 3}
B {1, 2, 3}
C [1, 2, 3]
D Error
Correct Answer:  B. {1, 2, 3}
EXPLANATION

Sets remove duplicate elements. set([1, 2, 2, 3, 3, 3]) returns {1, 2, 3}.

Take Test
Q.13 Hard Basics & Syntax
Consider: f = lambda x: x**2. What is f(5)?
A 10
B 25
C 5
D Error
Correct Answer:  B. 25
EXPLANATION

Lambda creates an anonymous function. f = lambda x: x2 creates a function that returns x squared. f(5) = 52 = 25.

Take Test
Q.14 Hard Basics & Syntax
What is the output of: print(*[1, 2, 3])?
A [1, 2, 3]
B 1 2 3
C 123
D Error
Correct Answer:  B. 1 2 3
EXPLANATION

The * operator unpacks the list. print(*[1, 2, 3]) becomes print(1, 2, 3) which prints '1 2 3' with spaces.

Take Test
Q.15 Hard Basics & Syntax
Consider: try: int('abc'); except: print('error'). What will be printed?
A Nothing
B 'error'
C error
D ValueError
Correct Answer:  C. error
EXPLANATION

int('abc') raises a ValueError. The except block catches it and prints 'error' (without quotes).

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

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

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

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

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

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