PyData Careers
20.9K subscribers
207 photos
4 videos
26 files
352 links
Python Data Science jobs, interview tips, and career insights for aspiring professionals.

Admin: @HusseinSheikho || @Hussein_Sheikho
Download Telegram
✖️ DON'T CREATE NESTED LISTS WITH THE * OPERATOR.

Because of this, you create a list containing multiple references to the very same inner list.
It looks like you're making a grid, but modifying one row will surprisingly change all of them. This is because the outer list just holds copies of the reference, not copies of the list itself.
Correct — use a list comprehension to ensure each inner list is a new, independent object.

Subscribe for more Python secrets!

# hidden error — all inner lists are the same object
matrix = [[]] * 3 # seems to create a 3x0 matrix

# append to the first row
matrix[0].append(99)

# all rows were modified!
print(matrix) # [[99], [99], [99]]


#  correct version — use a list comprehension
matrix_fixed = [[] for _ in range(3)]

# append to the first row
matrix_fixed[0].append(99)

# only the first row is modified, as expected
print(matrix_fixed) # [[99], [], []]


━━━━━━━━━━━━━━━
By: @DataScienceQ
5
🎁❗️TODAY FREE❗️🎁

Entry to our VIP channel is completely free today. Tomorrow it will cost $500! 🔥

JOIN 👇

https://t.iss.one/+MPpZ4FO2PHQ4OTZi
https://t.iss.one/+MPpZ4FO2PHQ4OTZi
https://t.iss.one/+MPpZ4FO2PHQ4OTZi
2
Checking Memory Usage in Python

psutil is imported, then through psutil.virtual_memory() memory data is obtained.

The function convert_bytes converts bytes to gigabytes.

Then the code calculates:

- total RAM
- available RAM
- used RAM
- percentage usage

And outputs this to the console.

import psutil

memory = psutil.virtual_memory()

def convert_bytes(size):
    # Convert bytes to GB
    gb = size / (1024 ** 3)
    return gb

total_gb = convert_bytes(memory.total)
available_gb = convert_bytes(memory.available)
used_gb = convert_bytes(memory.used)

print(f"Total RAM: {total_gb:.3f} GB")
print(f"Available RAM: {available_gb:.3f} GB")
print(f"Used RAM: {used_gb:.3f} GB")
print(f"RAM Usage: {memory.percent}%")


Or simply press CTRL + ALT + DELETE and open Task Manager. It has worked since the days of Windows 95.

The RAM usage percentage loses its meaning if you have Chrome open — it will consume everything on its own
😄

👉  https://t.iss.one/DataScienceQ
Please open Telegram to view this post
VIEW IN TELEGRAM
2
Interview Question

What can be a key in a dictionary?

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

tags: #interview

@DataScienceQ
Please open Telegram to view this post
VIEW IN TELEGRAM
4👏3
Question from the interview

Why does isinstance(True, int) return True?

Answer: In Python, bool is a subclass of int. True and False are instances of int with values 1 and 0, respectively.

tags: #interview

➡️ @DataScienceQ
Please open Telegram to view this post
VIEW IN TELEGRAM
6👍1🔥1
Python Quiz
Please open Telegram to view this post
VIEW IN TELEGRAM
7
Question from the interview

What is Big O notation?

Answer: Big O notation is a way of describing how quickly the running time or memory consumption of an algorithm increases as the size of the input data increases. It shows the asymptotic complexity: the upper bound of the algorithm's behavior, without taking into account constants and minor details.

For example, O(n) grows linearly, O(n²) - quadratically, O(1) - does not depend on the size of the input.

Big O does not give exact figures, but allows you to compare algorithms in terms of their scalability.


tags: #interview

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

What is __slots__?

Answer: By default, class instances store their attributes in the internal dictiondictct__. This is flexible, but it requires more memory and makes access to fields a bit slower, because the search is done in the dictionarslotsts__ allows you to fix a set of allowed attributes and abandon the usedictct__. Instead of a dictionary, Python allocates compact slots — thereby reducing the memory consumption for each object and speeding up access to attributes. This is especially important when millions of class instances are created in a program or the performance of data access is critical.

There is one restriction: it is not possible to add an attribute that is notslotsts__. To retain the ability to dynamically create fields, you can dictct__ to the list of slots.

tags:
#interview

@DataScienceQ
Please open Telegram to view this post
VIEW IN TELEGRAM
6👎1
❗️LISA HELPS EVERYONE EARN MONEY!$29,000 HE'S GIVING AWAY TODAY!

Everyone can join his channel and make money! He gives away from $200 to $5.000 every day in his channel

https://t.iss.one/+YDWOxSLvMfQ2MGNi

⚡️FREE ONLY FOR THE FIRST 500 SUBSCRIBERS! FURTHER ENTRY IS PAID! 👆👇

https://t.iss.one/+YDWOxSLvMfQ2MGNi
3
Question from the interview

What is a message broker and which ones are typically used with Python?

Answer: A message broker is an intermediary component that accepts messages from one service and delivers them to another, allowing microservices and asynchronous tasks to interact without direct connection. It ensures reliable delivery, queues, routing, and scalability.

In Python projects, RabbitMQ, Apache Kafka, and Redis are often used as simple broker solutions (for example, in combination with Celery). The choice depends on the tasks: Kafka for stream processing, RabbitMQ for flexible routing, and Redis for simple queues.


tags: #interview

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

What is an S3 storage and what is it used for?

Answer: S3 (Simple Storage Service) is a cloud-based object storage service designed for storing any type of files, from images and backups to static websites.

It is scalable, reliable, and provides access to files via URLs. Unlike traditional file systems, S3 does not have a folder hierarchy — everything is stored as objects in "buckets" (containers), and access can be controlled through policies and permissions.


tags: #interview

@DataScienceQ
Please open Telegram to view this post
VIEW IN TELEGRAM
6
Question from the interview

Why don't you need to store a session when using JWT?

Answer: JWT contains all the necessary information about the user directly in the token, including the expiration date and roles. The server simply verifies the token's signature and does not store any data between requests, so a separate session storage is not required.

tags: #interview

@DataScienceQ
Please open Telegram to view this post
VIEW IN TELEGRAM
3
What is NoneType?

NoneType — is a type to which the object None belongs, which is used to indicate an absent or undefined value. In Python, it is unique — there is only one instance of this type, that is, the None itself

@DataScienceQ 💚
Please open Telegram to view this post
VIEW IN TELEGRAM
3👍1
Question from the interview

I need to calculate 100 equations — is it worth using threads for this?

Answer:
If you need to calculate 100 equations in Python and it's a purely computational task without input-output, using threads is not advisable. In CPython, due to the GIL, calculations in threads are not performed in parallel, and switching threads only adds overhead.

For such tasks, it's better to use processes (multiprocessing, ProcessPoolExecutor) or move the calculations to native code (NumPy, C/C++ libraries). If the calculations are not large in size, parallelization may not pay off at all — then it's more reasonable to calculate sequentially.


tags: #interview

@DataScienceQ
Please open Telegram to view this post
VIEW IN TELEGRAM
3
This channels is for Programmers, Coders, Software Engineers.

0️⃣ Python
1️⃣ Data Science
2️⃣ Machine Learning
3️⃣ Data Visualization
4️⃣ Artificial Intelligence
5️⃣ Data Analysis
6️⃣ Statistics
7️⃣ Deep Learning
8️⃣ programming Languages

https://t.iss.one/addlist/8_rRW2scgfRhOTc0

https://t.iss.one/Codeprogrammer
Please open Telegram to view this post
VIEW IN TELEGRAM
2
Generated columns in PostgreSQL: speeding up filters without unnecessary calculations!

When the same expression is constantly calculated in WHERE, queries slow down. In PostgreSQL, this is solved with GENERATED ALWAYS AS … STORED — the expression is calculated once and stored as a regular field.

Create a table with a materialized expression:
CREATE TABLE events (
    id BIGSERIAL PRIMARY KEY,
    payload JSONB NOT NULL,
    event_type TEXT GENERATED ALWAYS AS (payload->>'type') STORED
);


Now event_type is no longer calculated on the fly — the value is directly in the row.

Filtering becomes easier and faster:
SELECT id
FROM events
WHERE event_type = 'purchase';


Add an index:
CREATE INDEX idx_events_event_type
    ON events(event_type);


Check:
EXPLAIN ANALYZE
SELECT id
FROM events
WHERE event_type = 'purchase';


🔥 There should be a Index Scan, without heavy operations on JSONB. Generated columns are great for repetitive calculations:

🚪 @DataScienceQ
Please open Telegram to view this post
VIEW IN TELEGRAM
5👏1
1. What data type is the variable rating = 4.9?
A. Integer
B. Float
C. String
D. Boolean
Correct answer: B.

2. What does the input() function always return?
A. Integer
B. Float
C. Boolean
D. String
Correct answer: D.

3. Which symbol is used to define a comment in Python?
A. //
B. /* */
C. #
D. --
Correct answer: C.

4. What does course[-1] return for a non-empty string?
A. First character
B. Last character
C. Second character
D. Entire string
Correct answer: B.

5. What is the result type of the / operator in Python?
A. Integer
B. Float
C. Boolean
D. String
Correct answer: B.

6. Which operator is used for exponentiation?
A. ^
B. *
C. **
D. //
Correct answer: C.

7. Which logical operator in Python negates a condition?
A. and
B. or
C. not
D. !=
Correct answer: C.

8. What does range(1, 5, 2) generate?
A. 1, 2, 3, 4
B. 1, 3
C. 2, 4
D. 0, 2, 4
Correct answer: B.

9. Which list method removes the last item?
A. remove()
B. delete()
C. pop()
D. clear()
Correct answer: C.

10. What is a tuple best described as?
A. A mutable list
B. A read-only list
C. A key/value store
D. A function container
Correct answer: B.

11. Which dictionary method safely returns a default value if a key is missing?
A. index()
B. find()
C. get()
D. pop()
Correct answer: C.

12. What is returned by a function that has no return statement?
A. 0
B. False
C. Empty string
D. None
Correct answer: D.

13. Which exception is raised when dividing by zero?
A. ValueError
B. TypeError
C. ZeroDivisionError
D. IndexError
Correct answer: C.

14. What is the purpose of the __init__ method in a class?
A. To delete objects
B. To initialize objects
C. To inherit methods
D. To define modules
Correct answer: B.

15. Which command installs a package from PyPI?
A. python install openpyxl
B. install pip openpyxl
C. pip add openpyxl
D. pip install openpyxl
Correct answer: D.
2👍1
PyData Careers
Photo
1. What will be the output of the following code?

def f(x, l=[]):
l.append(x)
return l

print(f(1))
print(f(2))


A. [1] then [2]
B. [1] then [1, 2]
C. Error due to mutable default
D. [] then []

Correct answer: B.

2. What is the result of this expression?

a = [1, 2, 3]
b = a
a += [4]


A. a = [1,2,3], b = [1,2,3]
B. a = [1,2,3,4], b = [1,2,3]
C. a = [1,2,3,4], b = [1,2,3,4]
D. Raises TypeError

Correct answer: C.

3. What does this code print?

print(bool([]), bool({}), bool(()))


A. True True True
B. False False False
C. False True False
D. True False True

Correct answer: B.

4. What is the output?

x = 10
def outer():
x = 20
def inner():
nonlocal x
x += 5
inner()
return x

print(outer())


A. 10
B. 20
C. 25
D. UnboundLocalError

Correct answer: C.

5. What happens when this code is executed?

class A:
def __init__(self):
self.x = 1

a = A()
a.__dict__['x'] = 2
print(a.x)


A. 1
B. 2
C. AttributeError
D. KeyError

Correct answer: B.

6. What is printed?

print([i for i in range(3)] is [i for i in range(3)])


A. True
B. False
C. SyntaxError
D. Depends on Python version

Correct answer: B.

7. What does this code output?

def gen():
yield from range(3)

print(list(gen()))


A. [0, 1, 2]
B. [1, 2, 3]
C. range(0, 3)
D. Error

Correct answer: A.

8. What is the result?

a = (1, 2, [3, 4])
a[2].append(5)
print(a)


A. Error: tuple is immutable
B. (1, 2, [3, 4])
C. (1, 2, [3, 4, 5])
D. (1, 2, 5)

Correct answer: C.

9. What does this print?

print({i: i*i for i in range(3)})


A. {0, 1, 4}
B. {0: 0, 1: 1, 2: 4}
C. [(0,0),(1,1),(2,4)]
D. Error

Correct answer: B.

10. What is the output?

print(type(lambda x: x))


A. <class 'function'>
B. <class 'lambda'>
C. <class 'callable'>
D. <class 'object'>

Correct answer: A.

11. What happens here?

try:
1 / 0
finally:
print("done")


A. Nothing is printed
B. ZeroDivisionError only
C. Prints "done" then raises ZeroDivisionError
D. Prints "done" only

Correct answer: C.

12. What is printed?

x = [1, 2, 3]
print(x[::-1] is x)


A. True
B. False
C. Error
D. Depends on interpreter

Correct answer: B.

13. What does this code demonstrate?

class A: pass
class B(A): pass
print(issubclass(B, A))


A. Duck typing
B. Multiple inheritance
C. Polymorphism
D. Inheritance

Correct answer: D.

14. What is the output?

print(all([0, 1, 2]), any([0, 1, 2]))


A. True True
B. False True
C. True False
D. False False

Correct answer: B.

15. What will this print?

x = 5
def f():
print(x)
x = 3

f()


A. 5
B. 3
C. UnboundLocalError
D. NameError

Correct answer: C.

16. What is the result?

a = {1, 2, 3}
b = {3, 2, 1}
print(a == b)


A. False
B. True
C. TypeError
D. Order dependent

Correct answer: B.

17. What does this output?

print(type((i for i in range(3))))


A. <class 'list'>
B. <class 'tuple'>
C. <class 'generator'>
D. <class 'iterator'>

Correct answer: C.

18. What is printed?

x = [1, 2, 3]
y = x.copy()
x.append(4)
print(y)


A. [1,2,3,4]
B. [4]
C. [1,2,3]
D. Error

Correct answer: C.

19. What does this evaluate to?

print(1 == True, 0 == False)


A. False False
B. True True
C. True False
D. False True

Correct answer: B.

20. What is the output?

def f():
try:
return 1
finally:
return 2

print(f())


A. 1
B. 2
C. None
D. RuntimeError

Correct answer: B.
5