Python Data Science Jobs & Interviews
20.3K subscribers
188 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
What is the result of the following Python line?

print(bool([]))


A) True
B) False
C) []
D) None

#Python #Beginner #CodingQuiz #BooleanLogic #LearnPython
Question 1 (Beginner):
What is the output of the following Python code?

print("5" * 3)

A) 15
B) 555
C) 5 5 5
D) Error

#Python #Beginner #StringOperations #CodingQuiz #LearnPython
Question 4 (Beginner):
Which of the following is not a valid Python data type?

A) tuple
B) map
C) set
D) float

#Python #DataTypes #Beginner #ProgrammingQuiz #LearnPython
1
Question 5 (Beginner):
What is the correct way to check if a key exists in a Python dictionary?

A) if key in dict.keys()
B) if dict.has_key(key)
C) if key.exists(dict)
D) if key in dict

#Python #Programming #DataStructures #Beginner
1
Question 20 (Beginner):
What is the output of this Python code?

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



A) [1, 2, 3]
B) [1, 2, 3, 4]
C) [4, 3, 2, 1]
D) Raises an error

#Python #Lists #Variables #Beginner

By: https://t.iss.one/DataScienceQ

**Correct answer: B) `[1, 2, 3, 4]`**

*Explanation:
- `y = x` creates a reference to the same list object
- Modifying `y` affects `x` because they point to the same memory location
- To create an independent copy, use
y = x.copy() or y = list(x)*
Question 21 (Beginner):
What is the correct way to check the Python version installed on your system using the command line?

A) python --version
B) python -v
C) python --v
D) python version

#Python #Basics #Programming #Beginner

By: https://t.iss.one/DataScienceQ
1
⁉️ Interview question
What happens when you call `plt.plot()` without specifying a figure or axes, and then immediately call `plt.show()`?

The function `plt.plot()` automatically creates a new figure and axes if none exist, and `plt.show()` displays the current figure. However, if multiple plots are created without clearing the figure, they may overlap or appear in unexpected orders due to matplotlib's internal state management. This behavior can lead to confusion, especially when working with loops or subplots.

#️⃣ tags: #matplotlib #python #datavisualization #plotting #beginner #codingchallenge

By: @DataScienceQ 🚀
⁉️ Interview question
How does `plt.subplot()` differ from `plt.subplots()` when creating a grid of plots?

`plt.subplot()` creates a single subplot in a grid by specifying row and column indices, requiring separate calls for each subplot. In contrast, `plt.subplots()` creates the entire grid at once, returning both the figure and an array of axes objects, making it more efficient for managing multiple subplots. However, using `plt.subplot()` can lead to overlapping or misaligned plots if not carefully managed, especially when adding elements like titles or labels.

#️⃣ tags: #matplotlib #python #plotting #subplots #datavisualization #beginner #codingchallenge

By: @DataScienceQ 🚀
⁉️ Interview question
What is the purpose of `scipy.integrate.quad()` and how does it handle functions with singularities?

`scipy.integrate.quad()` computes definite integrals using adaptive quadrature, which recursively subdivides intervals to improve accuracy. When dealing with functions that have singularities (e.g., discontinuities or infinite values), it may fail or return inaccurate results unless the integration limits are adjusted or the singularity is isolated. In such cases, splitting the integral at the singularity point or using specialized methods like `quad` with `points` parameter can help achieve better convergence, though improper handling might lead to warnings or unexpected outputs.

#️⃣ tags: #scipy #python #numericalintegration #scientificcomputing #mathematics #codingchallenge #beginner

By: @DataScienceQ 🚀
Please open Telegram to view this post
VIEW IN TELEGRAM
⁉️ Interview question
How does `scipy.optimize.minimize()` choose between different optimization algorithms, and what happens if the initial guess is far from the minimum?

`scipy.optimize.minimize()` selects an algorithm based on the `method` parameter (e.g., 'BFGS', 'Nelder-Mead', 'COBYLA'), each suited for specific problem types. If the initial guess is far from the true minimum, some methods may converge slowly or get stuck in local minima, especially for non-convex functions. The function also allows passing bounds and constraints to guide the search, but poor initialization can lead to suboptimal results or failure to converge, particularly when using gradient-based methods without proper scaling or preprocessing of input data.

#️⃣ tags: #scipy #python #optimization #scientificcomputing #numericalanalysis #machinelearning #codingchallenge #beginner

By: @DataScienceQ 🚀
1
Q: How can you create a simple Python script to manage a SQLite database for storing and retrieving user information, including adding new users, displaying all users, and searching by name? Provide a step-by-step example with basic error handling.

A:
import sqlite3

# Connect to database (creates if not exists)
conn = sqlite3.connect('users.db')
cursor = conn.cursor()

# Create table
cursor.execute('''
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT NOT NULL
)
''')
conn.commit()

# Add user function
def add_user(name, email):
try:
cursor.execute("INSERT INTO users (name, email) VALUES (?, ?)", (name, email))
conn.commit()
print(f"User {name} added.")
except sqlite3.Error as e:
print(f"Error: {e}")

# Display all users
def show_users():
cursor.execute("SELECT * FROM users")
users = cursor.fetchall()
if users:
for user in users:
print(f"ID: {user[0]}, Name: {user[1]}, Email: {user[2]}")
else:
print("No users found.")

# Search user by name
def search_user(name):
cursor.execute("SELECT * FROM users WHERE name LIKE ?", ('%' + name + '%',))
results = cursor.fetchall()
if results:
for user in results:
print(f"ID: {user[0]}, Name: {user[1]}, Email: {user[2]}")
else:
print("No user found.")

# Example usage
add_user("Alice", "[email protected]")
add_user("Bob", "[email protected]")

print("\nAll users:")
show_users()

print("\nSearching for 'Alice':")
search_user("Alice")

# Close connection
conn.close()

#Python #SQLite #Databases #Beginner #Programming #DatabaseManagement #SimpleCode #DataStorage #LearningPython

By: @DataScienceQ 🚀
1. What is a database?
2. Why do we use databases in Python?
3. Name a popular database library for Python.
4. How do you connect to a SQLite database in Python?
5. What is the purpose of cursor() in database operations?
6. How do you execute a query in Python using SQLite?

---

Explanation with Code Example (Beginner Level):

import sqlite3

# 1. Create a connection to a database (or create it if not exists)
conn = sqlite3.connect('example.db')

# 2. Create a cursor object to interact with the database
cursor = conn.cursor()

# 3. Create a table
cursor.execute('''
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
age INTEGER
)
''')

# 4. Insert data into the table
cursor.execute("INSERT INTO users (name, age) VALUES ('Alice', 25)")
cursor.execute("INSERT INTO users (name, age) VALUES ('Bob', 30)")

# 5. Commit changes
conn.commit()

# 6. Query the data
cursor.execute("SELECT * FROM users")
rows = cursor.fetchall()
for row in rows:
print(row)

# Close connection
conn.close()

This example shows how to:
- Connect to a SQLite database.
- Create a table.
- Insert and retrieve data.

Answer:
1. A database is an organized collection of data.
2. We use databases to store, manage, and retrieve data efficiently.
3. sqlite3 is a popular library.
4. Use sqlite3.connect() to connect.
5. cursor() allows executing SQL commands.
6. Use cursor.execute() to run queries.

#Python #Databases #SQLite #Beginner #Programming #Coding #LearnToCode

By: @DataScienceQ 🚀
1
1. What is a GUI?
2. Why use GUI in Python?
3. Name a popular GUI library for Python.
4. How do you create a window using Tkinter?
5. What is the purpose of mainloop() in Tkinter?
6. How do you add a button to a Tkinter window?

---

Explanation with Code Example (Beginner Level):

import tkinter as tk

# 1. Create the main window
root = tk.Tk()
root.title("My First GUI")

# 2. Add a label
label = tk.Label(root, text="Hello, World!")
label.pack()

# 3. Add a button
def on_click():
print("Button clicked!")

button = tk.Button(root, text="Click Me", command=on_click)
button.pack()

# 4. Run the application
root.mainloop()

This code creates a simple GUI window with a label and button.

Answer:
1. GUI stands for Graphical User Interface.
2. To create interactive applications with buttons, forms, etc.
3. Tkinter is a popular library.
4. Use tk.Tk() to create a window.
5. mainloop() keeps the window open and responsive.
6. Use tk.Button() and .pack() to add a button.

#Python #GUI #Tkinter #Beginner #Programming #Coding #LearnToCode

By: @DataScienceQ 🚀