Python Programming
Python fundamentals to advanced for interviews
56 Questions 10 Topics Take Test
Advertisement
Showing 41–50 of 56 questions
Q.41 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.

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

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

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

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

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

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

Take Test
Q.48 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().

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

Take Test
Q.50 Medium Basics & Syntax
What will be the output of: 'a' in 'apple'?
A True
B False
C 1
D Error
Correct Answer:  A. True
EXPLANATION

The 'in' operator checks for substring presence. 'a' is in 'apple', so it returns True.

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