Many GATE DA candidates from maths, statistics or non-CS backgrounds treat Python as the easy part of programming preparation. Then an output question combines aliasing, mutation and slicing, and familiar syntax produces an unfamiliar answer. The gap is not writing Python. It is tracing what each name refers to and knowing the cost of standard operations.
Three ideas carry almost every such question: a name is only a reference to an object, a mutation is visible through every name bound to that object, and the cost of an operation belongs to the container you chose rather than the syntax you typed.
What GATE DA asks in Python, not syntax recall
Python questions in the DA programming block can ask what a snippet prints, what value a variable holds after execution, how much time or space an operation needs, or which data structure fits a task. A method name is rarely the hard part. The hard part is following shared references, in-place changes and loop cost precisely.
That is why passive reading feels comfortable but does not transfer to a question. After each topic, predict the result before running the code. The Python Output-Based Questions collection is useful for turning that prediction habit into practice.
Names, objects and references unlock output questions
A Python variable is a name bound to an object. The assignment b = a binds another name to the same object; it does not copy the object's value into a separate box.
The consequence depends on mutability:
Lists, dictionaries and sets are mutable. Their contents can change while the object remains the same.
Integers, strings, tuples and frozensets are immutable. An apparent change binds the name to a different object.
Suppose a and b name one list. Calling a.append(4) mutates that list, so the change is visible through b too. In contrast, if x and y both refer to integer 3, executing x = x + 1 binds x to integer 4; it does not alter the integer object seen through y.
This names-to-objects picture explains most output questions that candidates call surprising.
Worked example: aliasing versus a shallow copy
Consider this snippet:
a = [1, 2, 3]
b = a
c = a[:]
a.append(4)
b.append(5)
print(a, b, c)Trace it one statement at a time:
anames a list containing[1, 2, 3].b = amakesbname the same list object asa.c = a[:]creates a fresh shallow copy containing[1, 2, 3].a.append(4)mutates the shared object to[1, 2, 3, 4].b.append(5)reaches that same object and mutates it to[1, 2, 3, 4, 5].cstill names its separate list, so it remains[1, 2, 3].
The exact output is:
[1, 2, 3, 4, 5] [1, 2, 3, 4, 5] [1, 2, 3]There are two list objects at the end, not three. One has five elements and two incoming names, while the other has three elements and one name. That object count is a quick way to check the trace.
![Two list objects after the trace: names a and b both point to [1, 2, 3, 4, 5], while c points to a separate [1, 2, 3].](https://kgai.blob.core.windows.net/blog-assets/blog_asset_1784055069281_nx0bku.jpg)
Complexity facts to memorise
Know the average case where hashing is involved, and know the worst case too, because a question can ask for either.
Operation | list | set | dict |
|---|---|---|---|
Subscript or index |
| Not supported | Average |
Membership with |
| Average | Average |
Append, add or update | Append amortised | Add average | Update average |
Insert at front |
| Not positional | Not positional |
For a concrete contrast, let a list contain n = 1,000,000 values. A missing-value test with x in a_list may inspect all one million elements, so it is O(n). A set uses a hash-backed average O(1) membership test. If an outer loop performs one such membership check for each of n items, list membership can make the whole pattern O(n^2), while average set membership makes it O(n).
Space follows the same reasoning. A slice copy such as a[:] needs O(n) extra space as well as O(n) time, so building one copy per iteration of a loop over n items turns a single linear pass into quadratic work.
This is not a licence to call every set operation guaranteed constant time. Hash collisions can produce an O(n) worst case. For exam analysis, state whether you mean average or worst-case complexity.

So pick the container by the cost of the operation you will repeat most often, not by habit: membership tests belong in a set, positional access in a list, and keyed lookup in a dict.
Traps GATE DA can set
Shallow and deep copy: a[:] creates a new outer list but does not clone nested objects. If a = [[1], [2]], then b = a[:] still shares the two inner lists. Use copy.deepcopy only when you really need an independent nested object graph.
a = [[1], [2]]
b = a[:]
a[0].append(9)
print(a, b) # [[1, 9], [2]] [[1, 9], [2]]is and ==: == asks whether values are equal. is asks whether two names refer to the same object. Integer and string interning can make some identity tests appear true, but that is an implementation detail, not a rule for value comparison. Use == for values.
Mutable default arguments: a default list is created once when the function is defined, then reused by later calls that omit that argument. Use None as the default and create a list inside the function.
def collect(item, bucket=[]):
bucket.append(item)
return bucket
print(collect(1)) # [1]
print(collect(2)) # [1, 2]In-place sort: items.sort() changes items and returns None. sorted(items) returns a new sorted list and leaves the original iterable alone.
items = [3, 1, 2]
print(items.sort()) # None
print(items) # [1, 2, 3]
print(sorted([3, 1, 2])) # [1, 2, 3]The safe routine is to draw names and objects before predicting output. Syntax-first reasoning misses shared state.
How to confirm the current GATE DA scope
In practice these appear as output MCQs and MSQs, complexity NAT questions and value-after-execution questions. Do not trust a forwarded syllabus PDF or an old section-weightage table. Confirm the current DA topics and paper information on the organising institute's official GATE exam papers and syllabus page.
Syllabus scope and paper details can change between cycles, so the official page is the only source to trust for them. Python's reference and mutation behaviour does not change between cycles, so that part of your preparation is safe to learn once.
Short version and next step
Hold three ideas together: names refer to objects, mutable objects can change through any alias, and operation cost depends on the structure. Then practise output snippets until you can draw the reference graph without effort.
Continue with the Python Programming course, then use the GATE category to keep the topic inside a complete exam plan. KnowledgeGate has more than 500 Python practice questions on lists, dictionaries, slicing and output prediction. Predict first, trace second, and run the code only after committing to an answer.




