Python Programming — Basics & Syntax
Python fundamentals to advanced for interviews
100 Questions 10 Topics Take Test
Advertisement
Showing 1–10 of 100 questions in Basics & Syntax
Q.1 Medium Basics & Syntax
Consider the following code snippet:

python
x = [1, 2, 3]
y = x
y.append(4)
print(x)


What will be the output?
A [1, 2, 3, 4]
B [1, 2, 3]
C Error: list object does not support append
D [4]
Correct Answer:  A. [1, 2, 3, 4]
EXPLANATION

In Python, when you assign y = x, both variables reference the same list object in memory. When you modify the list using y.append(4), the original list x is also modified because they point to the same object. Therefore, print(x) outputs [1, 2, 3, 4].

Take Test
Q.2 Medium Basics & Syntax
What is the output of: print(None == False)?
A True
B False
C None
D Error
Correct Answer:  B. False
EXPLANATION

None and False are distinct objects. None == False evaluates to False. None is a unique singleton object, not equivalent to False or 0.

Take Test
Q.3 Medium Basics & Syntax
Consider the code: x = (1, 2, 3); x[0] = 5. What happens?
A x becomes (5, 2, 3)
B TypeError is raised
C x remains (1, 2, 3)
D IndexError is raised
Correct Answer:  B. TypeError is raised
EXPLANATION

Tuples are immutable. Attempting to modify a tuple element with x[0] = 5 raises a TypeError: 'tuple' object does not support item assignment.

Take Test
What will be the output of: x = 5; x += 3; print(x)?
A 5
B 3
C 8
D Error
Correct Answer:  C. 8
EXPLANATION

x += 3 is equivalent to x = x + 3. Starting with x=5, after adding 3, x becomes 8.

Take Test
Q.5 Medium Basics & Syntax
Consider: d = {'a': 1, 'b': 2}; d['c'] = 3. What is d?
A {'a': 1, 'b': 2}
B {'a': 1, 'b': 2, 'c': 3}
C Error
D None
Correct Answer:  B. {'a': 1, 'b': 2, 'c': 3}
EXPLANATION

Dictionaries are mutable. The assignment d['c'] = 3 adds a new key-value pair to the dictionary. d becomes {'a': 1, 'b': 2, 'c': 3}.

Take Test
Advertisement
What is the output of: print('a' in 'banana')?
A True
B False
C 1
D Error
Correct Answer:  A. True
EXPLANATION

The 'in' operator checks if 'a' is a substring of 'banana'. It is present (multiple times), so it returns True.

Take Test
Q.7 Medium Basics & Syntax
Consider: x = [1, 2, 3, 4, 5]; y = x[1:4]. What is y?
A [1, 2, 3]
B [2, 3, 4]
C [2, 3, 4, 5]
D [1, 2, 3, 4]
Correct Answer:  B. [2, 3, 4]
EXPLANATION

List slicing x[1:4] includes indices 1, 2, 3 (but excludes 4). Elements are 2, 3, 4 from the list [1, 2, 3, 4, 5].

Take Test
What will be the output of: print(10 if 5 > 3 else 20)?
A 10
B 20
C True
D Error
Correct Answer:  A. 10
EXPLANATION

This is a ternary conditional expression. Since 5 > 3 is True, the expression evaluates to 10 (the value before 'if').

Take Test
Q.9 Medium Basics & Syntax
Consider the code: def func(x, y=5): return x + y. What is func(3)?
A 3
B 5
C 8
D Error
Correct Answer:  C. 8
EXPLANATION

y has a default value of 5. When func(3) is called, x=3 and y=5 (default). The function returns 3 + 5 = 8.

Take Test
Q.10 Medium Basics & Syntax
Consider: a = 'Hello'; b = 'Hello'. Are a and b the same object?
A Always True
B Always False
C Depends on interpreter implementation
D Cannot be determined
Correct Answer:  C. Depends on interpreter implementation
EXPLANATION

Due to string interning in Python, small strings may be cached and refer to the same object. However, this is an implementation detail. a == b is True, but a is b may vary.

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