Python Programming
Python fundamentals to advanced for interviews
119 Questions 10 Topics Take Test
Advertisement
Showing 41–50 of 119 questions
Q.41 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.42 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.43 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.44 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.45 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.46 Medium Basics & Syntax
What will be the output of: print('abc' * 3)?
A 'abc' 'abc' 'abc'
B 'abcabcabc'
C abcabcabc
D Error
Correct Answer:  C. abcabcabc
EXPLANATION

String multiplication repeats the string. 'abc' * 3 produces 'abcabcabc' and print displays it without quotes.

Take Test
Q.47 Medium Basics & Syntax
Consider: lst = [1, [2, 3], 4]. What is lst[1][0]?
A 1
B 2
C 3
D [2, 3]
Correct Answer:  B. 2
EXPLANATION

lst[1] refers to the nested list [2, 3]. lst[1][0] refers to the first element of that nested list, which is 2.

Take Test
Q.48 Medium Basics & Syntax
Consider: d = {1: 'a', 2: 'b', 3: 'c'}. What is d.get(4, 'default')?
A 'c'
B None
C 'default'
D Error
Correct Answer:  C. 'default'
EXPLANATION

The get() method returns a value for a key. If the key doesn't exist, it returns the default value provided.

Take Test
Q.49 Medium Basics & Syntax
What will be the result of: ' hello '.strip()?
A ' hello'
B 'hello '
C 'hello'
D 'HELLO'
Correct Answer:  C. 'hello'
EXPLANATION

The strip() method removes leading and trailing whitespace. ' hello '.strip() returns 'hello'.

Take Test
Q.50 Medium Basics & Syntax
Consider: result = [x*2 for x in range(3) if x > 0]. What is result?
A [0, 2, 4]
B [2, 4]
C [0, 1, 2]
D [1, 2, 3]
Correct Answer:  B. [2, 4]
EXPLANATION

List comprehension iterates through range(3) [0,1,2], filters x>0 [1,2], and multiplies by 2: [2, 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