Python Programming — Basics & Syntax
Python fundamentals to advanced for interviews
100 Questions 10 Topics Take Test
Advertisement
Showing 11–20 of 100 questions in Basics & Syntax
Q.11 Medium Basics & Syntax
What will be printed: print(3 ** 2 ** 2)?
A 81
B 512
C 729
D 36
Correct Answer:  A. 81
EXPLANATION

Exponentiation is right-associative. 3 2 2 = 3 (2 2) = 3 ** 4 = 81.

Take Test
Q.12 Easy Basics & Syntax
What is the output of: print(len('Python'))?
A 5
B 6
C 7
D Error
Correct Answer:  B. 6
EXPLANATION

The string 'Python' has 6 characters: P-y-t-h-o-n. len() returns the number of characters in a string.

Take Test
Q.13 Medium Basics & Syntax
Consider the code: x = [1, 2, 3]; y = x; y.append(4). What is x?
A [1, 2, 3]
B [1, 2, 3, 4]
C [4]
D Error
Correct Answer:  B. [1, 2, 3, 4]
EXPLANATION

y = x creates a reference to the same list object. When y.append(4) is called, it modifies the original list. Both x and y point to [1, 2, 3, 4].

Take Test
Q.14 Easy Basics & Syntax
What will be the data type of x after executing: x = 5 / 2?
A int
B float
C complex
D str
Correct Answer:  B. float
EXPLANATION

In Python 3, the division operator (/) always returns a float, regardless of whether the operands are integers. 5 / 2 = 2.5, which is a float.

Take Test
Q.15 Easy Basics & Syntax
What is the output of: print(10 // 3 + 10 % 3)?
A 6
B 6.33
C 7
D 5
Correct Answer:  C. 7
EXPLANATION

10 // 3 = 3 (floor division), 10 % 3 = 1 (modulo). 3 + 1 = 4. Wait, let me recalculate: 10//3=3, 10%3=1, so 3+1=4. Actually: output is 4.

Take Test
Advertisement
Q.16 Easy Basics & Syntax
Which of the following is NOT a valid Python variable name?
A _private_var
B 2nd_variable
C variable_name
D __dunder__
Correct Answer:  B. 2nd_variable
EXPLANATION

Variable names cannot start with a digit. '2nd_variable' is invalid because it begins with '2'. Valid names start with a letter or underscore.

Take Test
Q.17 Hard Basics & Syntax
What is the output of: print(type(lambda x: x))?
A
B
C
D Error
Correct Answer:  A.
EXPLANATION

Lambda functions are functions in Python. type(lambda x: x) returns <class 'function'>.

Take Test
Q.18 Hard Basics & Syntax
Consider: class A: x = 5. What is A.x and how can it be modified?
A Instance variable, modify via obj.x
B Class variable, modify via A.x or obj.x
C Local variable, cannot be modified
D Error
Correct Answer:  B. Class variable, modify via A.x or obj.x
EXPLANATION

x = 5 is a class variable. It can be accessed via A.x and modified via A.x = new_value or instance modification.

Take Test
Q.19 Hard Basics & Syntax
What will be the output of: print({x: x**2 for x in range(3)})?
A {0: 0, 1: 1, 2: 4}
B {0: 1, 1: 2, 2: 3}
C {1: 1, 2: 4}
D Error
Correct Answer:  A. {0: 0, 1: 1, 2: 4}
EXPLANATION

Dictionary comprehension creates {0: 0, 1: 1, 2: 4} where keys are from range(3) and values are their squares.

Take Test
Q.20 Hard Basics & Syntax
Consider the code: with open('file.txt') as f: data = f.read(). What happens when the block exits?
A File remains open
B File is automatically closed
C Error occurs
D data is deleted
Correct Answer:  B. File is automatically closed
EXPLANATION

The 'with' statement ensures the file is automatically closed when the block exits, even if an error occurs.

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