Python Data Science Jobs & Interviews
20.7K subscribers
192 photos
4 videos
26 files
335 links
Your go-to hub for Python and Data Science—featuring questions, answers, quizzes, and interview tips to sharpen your skills and boost your career in the data-driven world.

Admin: @Hussein_Sheikho
Download Telegram
Interview Question

Which tasks parallelize well, and which do not?

Answer: Tasks with a large number of input-output operations scale well with multithreading — network requests, file access, waiting for database responses. While one thread is waiting, the interpreter can switch to another without wasting time.

Tasks that heavily load the CPU and actively use memory parallelize poorly. In Python, this is especially noticeable due to the GIL: CPU-bound calculations will still use only one thread, and parallel execution will not provide a speedup. Moreover, due to thread switching, the program may even slow down.

If a task combines IO and heavy processing — for example, downloading and parsing — it is better to separate it: keep IO in threads, and assign CPU load to processes (via multiprocessing) or move it to a queue.


tags: #interview

@DataScienceQ
Please open Telegram to view this post
VIEW IN TELEGRAM
1
Interview question

What is the order of execution of decorators if there are several on one function?

Answer: Decorators are executed from bottom to top — the bottom one is called first, then the upper one, wrapping the function in several layers.

tags: #interview

@DataScienceQ
Please open Telegram to view this post
VIEW IN TELEGRAM
Interview question

What is the difference between using tensor.detach() and wrapping code in with torch.no_grad()?

Answer: with torch.no_grad() is a context manager that globally disables gradient calculation for all operations within its block. It's used during inference to reduce memory usage and speed up computation. tensor.detach() is a tensor-specific method that creates a new tensor sharing the same data but detached from the current computation graph. This stops gradients from flowing back to the original graph through this tensor, effectively creating a fork.

tags: #interview #pytorch #machinelearning

@DataScienceQ
Interview question

When saving a PyTorch model, what is the difference between saving the entire model versus saving just the model's state_dict? Which approach is generally recommended and why?

Answer: Saving the entire model (torch.save(model, PATH)) pickles the entire Python object, including the model architecture and its parameters. Saving just the state_dict (torch.save(model.state_dict(), PATH)) saves only a dictionary of the model's parameters (weights and biases).

The recommended approach is to save the
state_dict because it is more flexible and robust. It decouples the saved weights from the specific code that defined the model, making your code easier to refactor and share without breaking the loading process.

tags: #interview #pytorch #machinelearning

@DataScienceQ

━━━━━━━━━━━━━━━
By: @DataScienceQ
Interview question

What is the purpose of a pooling layer in a Convolutional Neural Network (CNN)?

Answer: A pooling layer (like Max Pooling or Average Pooling) is used to progressively reduce the spatial size (width and height) of the feature maps. This serves two main purposes: 1) It reduces the number of parameters and computational complexity, which helps to control overfitting. 2) It introduces a degree of translation invariance, meaning the network becomes more robust to small shifts and distortions in the position of features in the input image.

tags: #interview #cnn #deeplearning

━━━━━━━━━━━━━━━
By: @DataScienceQ
Interview question

What is the difference between the == (loose comparison) and === (strict comparison) operators in PHP?

Answer: The == operator is for loose comparison, checking for value equality after type juggling. For example, 1 == "1" is true. The === operator is for strict comparison, checking for both value AND type equality, without any type conversion. So, 1 === "1" is false. It's generally safer to use === to avoid unexpected bugs.

tags: #interview #php

━━━━━━━━━━━━━━━
By: @DataScienceQ
Interview question

What is the difference between isset() and empty() in PHP?

Answer: isset() returns true only if a variable is declared and is not NULL. In contrast, empty() returns true if a variable is considered "falsy", which includes NULL, false, 0, "0", an empty string "", or an empty array. A key difference is that a variable like $var = 0; is set (so isset() is true), but also considered empty (so empty() is true).

tags: #interview #php

━━━━━━━━━━━━━━━
By: @DataScienceQ
1
Interview question

Why is it better to use os.path.join() to construct paths instead of simple string concatenation?

Answer: Because os.path.join() handles cross-platform compatibility automatically. Operating systems use different path separators (e.g., / for Linux/macOS and \ for Windows). Hardcoding a separator like 'folder' + '/' + 'file' will break on a different OS. os.path.join('folder', 'file') correctly produces folder/file or folder\file depending on the system, making the code robust and portable.

tags: #interview #python #os

━━━━━━━━━━━━━━━
By: @DataScienceQ
1
Interview Question

How to get the current module's name?

Answer: The module name is available through the built-in variable name. If the module is imported, name contains its full name in the namespace. If the module is run as the main script, name automatically takes the value "main".

tags:
#interview

@DataScienceQ
Please open Telegram to view this post
VIEW IN TELEGRAM
1
Interview question

When would you use the __slots__ attribute in a Python class, and what is its main trade-off?

Answer: The __slots__ attribute is used for memory optimization. By defining it in a class, you prevent the creation of a __dict__ for each instance, instead allocating a fixed amount of space for the specified attributes. This is highly effective when creating a large number of objects. The primary trade-off is that you lose the ability to add new attributes to instances at runtime.

tags: #python #interview

━━━━━━━━━━━━━━━
By: @DataScienceQ
Interview question

What is None in Python?

Answer: None is a special value that represents the absence of a value or emptiness. It is used to indicate that a variable or function does not have a meaningful value. None is an object and the only value of the NoneType type. In Python, None is also used as the default value for function arguments if the argument was not explicitly provided.

tags: #interview

@DataScienceQ
Please open Telegram to view this post
VIEW IN TELEGRAM
Interview question

What is GIL in Python, why is it needed, and how can it be bypassed?

Answer: GIL (Global Interpreter Lock) is a mechanism in the CPython interpreter that ensures only one thread can execute Python bytecode at a time. It was introduced to simplify memory management and ensure thread safety of built-in data structures.

However, due to the GIL, multithreading in Python does not provide true CPU-level parallelism: even if multiple threads are created, they will run sequentially rather than simultaneously, which limits performance in computationally intensive tasks.

This limitation can be bypassed by using modules like multiprocessing, which run separate processes with their own memory and their own GIL. Heavy logic can also be moved to native C extensions or interpreters without a GIL, such as Jython or experimental versions of PyPy.


tags: #interview

@DataScienceQ
Please open Telegram to view this post
VIEW IN TELEGRAM
Interview question

What is the difference between asynchrony, multithreading, and multiprocessing?

Answer: Asynchrony works within a single thread and does not block program execution — while some operations wait for I/O completion, others continue running.

Multithreading uses multiple threads within one process that share memory and can run in parallel with coordination among them.

Multiprocessing launches several isolated processes, each with its own address space and resources, allowing true parallelism at the CPU level.

Simply put, asynchrony is efficient for I/O tasks, threads are used for tasks with shared data, and processes are for resource-intensive computations where load distribution across cores is important.


tags: #interview

@DataScienceQ
Please open Telegram to view this post
VIEW IN TELEGRAM
1
Interview Question

How to view an object's methods?

Answer: To see all methods and attributes associated with a specific object, you can use the dir() function. It takes the object as an argument and returns a list of all attribute and method names of the object.

tags: #interview

@DataScienceQ
Please open Telegram to view this post
VIEW IN TELEGRAM
2🔥1
Interview Question

What is the GIL (Global Interpreter Lock) in Python, and how does it impact the execution of multi-threaded programs?

Answer: The Global Interpreter Lock (GIL) is a mutex (or a lock) that allows only one thread to hold the control of the Python interpreter at any one time. This means that in a CPython process, only one thread can be executing Python bytecode at any given moment, even on a multi-core processor.

This has a significant impact on performance:

For CPU-bound tasks: Multi-threaded Python programs see no performance gain from multiple CPU cores. If you have a task that performs heavy calculations (e.g., image processing, complex math), creating multiple threads will not make it run faster. The threads will execute sequentially, not in parallel, because they have to take turns acquiring the GIL.

For I/O-bound tasks: The GIL is less of a problem. When a thread is waiting for Input/Output (I/O) operations (like waiting for a network response, reading from a file, or querying a database), it releases the GIL. This allows another thread to run. Therefore, the threading module is still highly effective for tasks that spend most of their time waiting, as it allows for concurrency.

How to achieve true parallelism?

To bypass the GIL and leverage multiple CPU cores for CPU-bound tasks, you must use the multiprocessing module. It creates separate processes, each with its own Python interpreter and memory space, so the GIL of one process does not affect the others.

tags: #Python #Interview #CodingInterview #GIL #Concurrency #Threading #Multiprocessing #SoftwareEngineering

━━━━━━━━━━━━━━━
By: @DataScienceQ
1
Interview question

What objects can be put into a set?

Answer: In Python, a set can only contain hashable (i.e., immutable) objects. This means you can put numbers, strings, tuples (if all their elements are also hashable), boolean values, and other immutable types into a set.

Objects like list, dict, set, and other mutable structures cannot be put in: they do not have a hash function (hash) and will cause a TypeError.

ta
gs: #interview

@DataScienceQ
Please open Telegram to view this post
VIEW IN TELEGRAM
1
Interview Question

What can be a key in a dictionary?

Answer: Dictionaries in Python are hash tables. Instead of keys, hashes are used in the dictionary. Accordingly, any hashable data type can be a key in the dictionary, which means all immutable data types.

tags: #interview

➡️ @DataScienceQ
Please open Telegram to view this post
VIEW IN TELEGRAM
3
Interview Question

What is a deep copy?

Answer: A deep copy is a complete duplication of an object along with all nested structures. Changes to the original do not affect the copy, and vice versa.

In Python, this is done using copy.deepcopy(), which creates a fully independent data structure, including nested lists, dictionaries, and other objects.


tags: #interview

@DataScienceQ
Please open Telegram to view this post
VIEW IN TELEGRAM
👍41
Interview Question

Why does list.sort() return None instead of the sorted list?

Answer: The list.sort() method modifies the list in place and intentionally returns None to clearly indicate that the sorting was done but no new list was created. This prevents confusion between modifying the object and creating its copy.

If a new sorted list is needed, the built-in sorted() function is used, which returns the result without changing the original.


tags: #interview

@DataScienceQ
Please open Telegram to view this post
VIEW IN TELEGRAM
Interview Question

Are there generics in Python like in Java or C++?

Answer: Yes, but only at the annotation level. Since Python 3.5, generic types (List[T], Dict[K, V]) have appeared through the typing module, but they are intended for static checking and do not affect the program's behavior at runtime.

tags: #interview

@DataScienceQ
Please open Telegram to view this post
VIEW IN TELEGRAM