EXAM Flashcards

1
Q

What are two differences between threads and processes in Python?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the role and impact of the Global Interpreter Lock (GIL) in Python?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a pure function in Python?

A

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).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is currying in Python?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the advantage of functions being first-class objects in Python for decorators?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the advantage of functions being first-class objects in Python for partial functions?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly