EXAM Flashcards
What are two differences between threads and processes in Python?
Memory: Threads share the same memory space, while processes have separate memory spaces.
Concurrency: Threads can be more efficient for I/O-bound tasks, while processes are better for CPU-bound tasks due to the Global Interpreter Lock (GIL) limitation on threads.
What is the role and impact of the Global Interpreter Lock (GIL) in Python?
mechanism in some programming languages (like Python) that ensures only one thread can execute at a time within the interpreter. While it simplifies memory management, it limits the ability to run multiple threads simultaneously on multi-core systems, which can reduce performance in tasks that are heavy on CPU processing.
What is a pure function in Python?
A pure function is a function where the output is only determined by its input values, with no side effects (such as modifying global variables or I/O operations).
What is currying in Python?
Currying is the process of transforming a function that takes multiple arguments into a sequence of functions, each taking a single argument. It allows for the partial application of functions.
What is the advantage of functions being first-class objects in Python for decorators?
First-class functions allow decorators to take a function as input, modify or enhance its behavior, and return a new function, enabling powerful and reusable design patterns.
What is the advantage of functions being first-class objects in Python for partial functions?
First-class functions enable the creation of partial functions by fixing some arguments of a function and returning a new function, allowing for customization and reuse of code.