0% found this document useful (0 votes)
3 views1 page

Advanced Python Interview Questions

The document provides advanced Python interview questions and answers, covering topics such as decorators, generators, Global Interpreter Lock (GIL), multithreading vs multiprocessing, context managers, and shallow vs deep copy. Each concept is explained with concise definitions and code examples. This serves as a useful resource for preparing for technical interviews in Python programming.

Uploaded by

minar.rhman
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Advanced Python Interview Questions

The document provides advanced Python interview questions and answers, covering topics such as decorators, generators, Global Interpreter Lock (GIL), multithreading vs multiprocessing, context managers, and shallow vs deep copy. Each concept is explained with concise definitions and code examples. This serves as a useful resource for preparing for technical interviews in Python programming.

Uploaded by

minar.rhman
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Advanced Python Interview Questions with Code

Examples

What is a decorator?
A decorator modifies the behavior of a function without changing its code.
def my_decorator(func): def wrapper(): print("Before") func()
print("After") return wrapper @my_decorator def say_hi(): print("Hi")

What is a generator?
A generator yields values one at a time using yield.
def count_up(n): for i in range(n): yield i

What is GIL?
Global Interpreter Lock ensures only one thread executes Python bytecode at a time.

What is multithreading vs multiprocessing?


Threads share memory, processes have separate memory.
from multiprocessing import Process def task(): print("Running") p =
Process(target=task) [Link]()

What is context manager?


Manages resources automatically.
with open("[Link]", "w") as f: [Link]("Hello")

What is shallow vs deep copy?


Deep copy duplicates nested objects.
import copy a = [[1,2]] b = [Link](a)

You might also like