What happens to a
list if you delete almost all its elements?Answer:
tags: #interview
Please open Telegram to view this post
VIEW IN TELEGRAM
❤3
Why is
list.sort() faster than sorted(list) when sorting the same list?Answer:
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
Please open Telegram to view this post
VIEW IN TELEGRAM
🔥3❤2
❔ Python Interview Question
Why is
Answer: Using
tags: #interview
➡ @DataScienceQ
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
What is the difference between "
is" and "=="? Answer:
tags: #interview
Please open Telegram to view this post
VIEW IN TELEGRAM
❤3
What is the structure of a JWT token?
Answer:
These parts are base64 encoded and joined by dots: header.payload.signature.
tags: #interview
Please open Telegram to view this post
VIEW IN TELEGRAM
❤2
What is Dependency Injection and how is it used in Python?
Answer:
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
Please open Telegram to view this post
VIEW IN TELEGRAM
❤3
What are the parts of an HTTP request?
Answer:
tags: #interview
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 ⭐️
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
Please open Telegram to view this post
VIEW IN TELEGRAM
❔ Interview Question
What is the difference between
tags: #interview #python #magicmethods #classes
➡️ @DataScienceQ 🤎
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
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
tags: #interview #python #generators #memory
@DataScienceQ⭐️
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
Why can
frozenset be a key in a dict, but set cannot?Answer:
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
Telegram
Python Data Science Jobs & Interviews
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
Admin: @Hussein_Sheikho
❤4
Which tasks parallelize well, and which do not?
Answer:
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
Please open Telegram to view this post
VIEW IN TELEGRAM
❤1
What is the order of execution of decorators if there are several on one function?
Answer:
tags: #interview
Please open Telegram to view this post
VIEW IN TELEGRAM
❔ Interview question
What is the difference between using
Answer: 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. 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
What is the difference between using
tensor.detach() and wrapping code in with torch.no_grad()?Answer:
with torch.no_grad()tensor.detach()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
Answer:Saving the entire model ( ) pickles the entire Python object, including the model architecture and its parameters. Saving just the ( ) saves only a dictionary of the model's parameters (weights and biases).
The recommended approach is to save the 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 ✨
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:
torch.save(model, PATH)state_dicttorch.save(model.state_dict(), PATH)The recommended approach is to save the
state_dicttags: #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 ✨
What is the purpose of a pooling layer in a Convolutional Neural Network (CNN)?
Answer:
tags: #interview #cnn #deeplearning
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
❔ Interview question
What is the difference between the
Answer: Theis for loose comparison, checking for value equality after type juggling. For example, is for strict comparison, checking for both value AND type equality, without any type conversion. So, to use to avoid unexpected bugs.
tags: #interview #php
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
What is the difference between the
== (loose comparison) and === (strict comparison) operators in PHP?Answer: The
== operator 1 == "1" is true. The === operator 1 === "1" is false. It's generally safer ===tags: #interview #php
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
❔ Interview question
What is the difference between
Answer:only if a variable is declared and is not . In contrast, is considered "falsy", which includes or an empty array. A key difference is that a variable like is set (so is true), but also considered empty (so is true).
tags: #interview #php
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
What is the difference between
isset() and empty() in PHP?Answer:
isset() returns true NULLempty() returns true if a variable NULL, false, 0, "0", an empty string "", $var = 0; isset()empty()tags: #interview #php
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
❤1
❔ Interview question
Why is it better to use
Answer: Becausehandles cross-platform compatibility automatically. Operating systems use different path separators (e.g., for Linux/macOS and for Windows). Hardcoding a separator like will break on a different OS. or depending on the system, making the code robust and portable.
tags: #interview #python #os
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
Why is it better to use
os.path.join() to construct paths instead of simple string concatenation?Answer: Because
os.path.join() /\'folder' + '/' + 'file' os.path.join('folder', 'file') correctly produces folder/filefolder\filetags: #interview #python #os
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
❤1
How to get the current module's name?
Answer:
tags:
Please open Telegram to view this post
VIEW IN TELEGRAM
❤1