Python Interview Questions for Freshers
The short answer
Python interviews for freshers stay on the basics: 11 questions here include list versus tuple, how a dictionary works, *args and **kwargs, decorators and list comprehensions. For each, read what a good answer covers, then explain it aloud in about a minute.
11 questions. Open one to see what a good answer covers.
What is the difference between a list and a tuple in Python?
A list is mutable and a tuple is immutable. Tuples are slightly faster, can be used as dictionary keys if their items are hashable, and suit fixed records. Lists suit collections that change.
How does a Python dictionary work?
It is a hash table that maps keys to values, with average constant-time lookup. Keys must be hashable, and since Python 3.7 a dictionary keeps insertion order.
What are *args and **kwargs?
*args collects extra positional arguments into a tuple and **kwargs collects extra keyword arguments into a dictionary. They let a function accept any number of arguments.
What is a decorator in Python?
A function that takes a function and returns a new one that adds behaviour, such as logging or timing, without changing the original code. It is written with the @ syntax.
What is the difference between == and is?
== checks whether two values are equal, while is checks whether they are the same object in memory. Use is for None checks, and == for comparing values.
What is a list comprehension?
A short way to build a list from another sequence, like [x * x for x in numbers if x > 0]. It is usually clearer and faster than a loop that appends.
How does Python manage memory?
Mainly by reference counting, where an object is freed when nothing refers to it, plus a garbage collector that finds reference cycles. Python also pools small objects.
What is the difference between a shallow copy and a deep copy?
A shallow copy copies the outer object but shares the inner objects, so changing a nested item shows in both. A deep copy copies everything inside too. Use copy.deepcopy for nested data.
What are generators and why use them?
Functions that use yield to produce values one at a time instead of building a whole list. They save memory and are good for large or endless streams of data.
What is the GIL?
The Global Interpreter Lock in CPython lets only one thread run Python bytecode at a time. Threads still help with waiting on input and output, but for heavy computation use multiprocessing.
Why is a mutable default argument a problem?
The default value is created once when the function is defined, so a default list is shared between calls. Use None as the default and create the list inside the function.
Everything runs in your browser. What you type is not sent anywhere.
How to: Python Interview Questions for Freshers
- 1Read the question and write a two-line answer from memory.
- 2Open the tip and compare it with what you wrote.
- 3Type a small example in Python to prove you can show it, not just say it.
- 4Use practice mode to answer aloud with a 60-second timer.
At a glance
- Questions
- 11 Python questions
- Includes
- Lists and tuples, dictionaries, decorators, comprehensions
- Time to aim for
- About 60 seconds each
Frequently asked questions
Do I need to write code in a Python interview?
Often yes, in small pieces. Be ready to write a function or a short loop on paper or a shared screen, and explain what each line does.
What is the difference between == and is?
== compares values, while is checks whether two names point to the very same object. It is one of the most asked basics, and the bank has a note on it.
More quick answers
- HR Interview Questions for Freshers: Tell Me About Yourself
- Behavioural Interview Questions and the STAR Method
- Java Interview Questions for Freshers
- SQL Interview Questions for Freshers
- Data Structures and Algorithms Interview Questions for Freshers
- Web Development Interview Questions for Freshers
- CS Fundamentals Interview Questions: OOP, OS and Networks
- Excel and Data Analysis Interview Questions for Freshers