Home Subjects Python Programming Basics & Syntax

Python Programming
Basics & Syntax

Python fundamentals to advanced for interviews

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

all() returns True if all elements are True. Since all three elements are True, the output is True.

Test
Q.32 Medium Basics & Syntax
Which of the following code snippets will execute without raising a NameError?
A print(undefined_variable)
B x = 5; print(x)
C print(y) where y is not defined
D print(2 + undefined)
Correct Answer:  B. x = 5; print(x)
EXPLANATION

Only option B defines x before using it. Other options reference undefined variables, causing NameError.

Test
Q.33 Medium Basics & Syntax
What will be the output of: x = '10'; y = int(x); print(y + 5)?
A '15'
B 15
C '105'
D Error
Correct Answer:  B. 15
EXPLANATION

int(x) converts the string '10' to integer 10. Adding 5 gives 15 (integer addition).

Test
Q.34 Medium Basics & Syntax
What will be the output of: print('a' * 3 + 'b' * 2)?
A aaabb
B aabbb
C ababab
D ab ab
Correct Answer:  A. aaabb
EXPLANATION

'a' * 3 produces 'aaa' and 'b' * 2 produces 'bb'. Concatenating gives 'aaabb'.

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

append() adds an element to the list. After adding 4, the list has 4 elements, so len(x) = 4.

Test
Q.36 Medium Basics & Syntax
What will be the output of: print(max([3, 1, 4, 1, 5, 9, 2, 6]))?
A 9
B 6
C 8
D 1
Correct Answer:  A. 9
EXPLANATION

The max() function returns the largest element in the list, which is 9.

Test
Q.37 Medium Basics & Syntax
Which of the following is a valid variable name in Python?
A 2variable
B var-iable
C var_iable
D var iable
Correct Answer:  C. var_iable
EXPLANATION

Variable names can contain letters, digits, and underscores, but cannot start with a digit or contain hyphens or spaces.

Test
Q.38 Medium Basics & Syntax
What will be the output of: print(abs(-5) + abs(3))?
A 2
B 8
C −2
D -8
Correct Answer:  B. 8
EXPLANATION

abs(-5) = 5 and abs(3) = 3. Therefore, 5 + 3 = 8.

Test
Q.39 Medium Basics & Syntax
What will be the output of: print(type({}))?
A
B
C
D
Correct Answer:  B.
EXPLANATION

Empty curly braces {} create an empty dictionary, not a set. To create an empty set, use set().

Test
Q.40 Medium Basics & Syntax
What will be the output of: x = 5; y = x; y = 10; print(x)?
A 5
B 10
C 15
D Error
Correct Answer:  A. 5
EXPLANATION

x and y are separate variables. Assigning y = 10 doesn't change x, which remains 5.

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