Python Data Science Jobs & Interviews
20.3K subscribers
187 photos
4 videos
25 files
325 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

What happens to a list if you delete almost all its elements?

Answer: list in Python does not automatically reduce allocated memory after deleting elements. For example, if the list had 1,000,000 elements and only 100 remain, it still occupies memory for a million elements until it is recreated (lst = lst[:] or lst = list(lst)).

tags: #interview

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

Why is list.sort() faster than sorted(list) when sorting the same list?

Answer: The list.sort() method performs an in-place sort, modifying the original list without creating a new copy. This makes it more efficient in terms of memory and performance.

The sorted(list) function creates a new sorted list, which requires additional memory allocation and copying of elements before sorting, potentially increasing time and memory costs.


tags: #interview

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

Why is dict.get(key) often preferred over directly accessing keys in a dictionary using dict[key]?

Answer: Using dict.get(key) avoids a KeyError if the key doesn't exist by returning None (or a default value) instead. Direct access with dict[key] raises an exception when the key is missing, which can interrupt program flow and requires explicit error handling.

tags: #interview

@DataScienceQ
1
Interview question

What is the difference between "is" and "=="?

Answer: The "is" operator checks whether two objects are the same object in memory, whereas the "==" operator checks whether the values of those objects are equal.

tags: #interview

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

What is the structure of a JWT token?

Answer: JWT (JSON Web Token) consists of three parts separated by dots:

▶️ Header — contains the token type (JWT) and the signing algorithm, such as HMAC SHA256 or RSA

▶️ Payload — includes so-called “claims”: data like user ID, token expiration, roles, and other metadata

▶️ Signature — created from the header and payload using a secret key. It ensures the token’s content has not been tampered with.

These parts are base64 encoded and joined by dots: header.payload.signature.


tags: #interview

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

What is Dependency Injection and how is it used in Python?

Answer: Dependency Injection is a technique where an object receives external dependencies (such as classes, functions, settings) through parameters rather than creating them internally.

In Python, DI is most often implemented explicitly: dependencies are passed to constructors, functions, or arguments, which increases code modularity and facilitates testing. For example, you can easily replace a service with a mock during unit testing.

Unlike Java, where DI containers like Spring are common, Python usually uses explicit dependency passing but can use libraries like dependency-injector for more complex automation if needed.


tags: #interview

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

What are the parts of an HTTP request?

Answer: An HTTP request consists of a start line (defines the type of message), headers (transmit transfer parameters and message characteristics), and the message body (contains data, separated from the headers by a blank line).

tags: #interview

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

What is a list comprehension in Python and how does it work?

Answer: A list comprehension is a concise way to create lists in Python by applying an expression to each item in an iterable, optionally with a condition (e.g., [x**2 for x in range(10) if x % 2 == 0]), making code more readable and efficient than traditional for loops for generating lists.

tags: #interview

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

What is the difference between __str__ and __repr__ methods in Python classes, and when would you implementstr
__str__ returns a human-readable string representation of an object (e.g., via print(obj)), making it user-friendly for displayrepr__repr__ aims for a more detailed, unambiguous string that's ideally executable as code (like repr(obj)), useful for debugging—imstr __str__ for end-user outrepr__repr__ for developer tools or str __str__ is defined.

tags: #interview #python #magicmethods #classes

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

Explain the concept of generators in Python and how they differ from regular iterators in terms of memory efficiency.

Generators are functions that use yield to produce a sequence of values lazily (e.g., def gen(): yield 1; yield 2), creating an iterator that generates items on-the-fly without storing the entire sequence in memory, unlike regular iterators or lists which can consume more RAM for large datasets—ideal for processing big data streams efficiently.

tags: #interview #python #generators #memory

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

Why can frozenset be a key in a dict, but set cannot?

Answer: Keys in a dict must be hashable, meaning their value must not change after creation.

frozenset is immutable, so its hash can be computed once and used as a key.

set is mutable, its contents can change, so its hash function is unstable, which is why dict does not allow using set as a key.


tags: #interview

https://t.iss.one/DataScienceQ 🖕
Please open Telegram to view this post
VIEW IN TELEGRAM
4
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