Python Data Science Jobs & Interviews
20.5K subscribers
191 photos
4 videos
25 files
332 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
Python Question / Quiz;

What is the output of the following Python code, and why? πŸ€”πŸš€ Comment your answers below! πŸ‘‡

#python #programming #developer #programmer #coding #coder #softwaredeveloper #computerscience #webdev #webdeveloper #webdevelopment #pythonprogramming #pythonquiz #ai #ml #machinelearning #datascience

https://t.iss.one/DataScienceQ
πŸ‘4
Python Question / Quiz;

What is the output of the following Python code, and why? πŸ€”πŸš€ Comment your answers below! πŸ‘‡

#python #programming #developer #programmer #coding #coder #softwaredeveloper #computerscience #webdev #webdeveloper #webdevelopment #pythonprogramming #pythonquiz #ai #ml #machinelearning #datascience

https://t.iss.one/DataScienceQ
πŸ‘2❀1
Python Question / Quiz;

What is the output of the following Python code, and why? πŸ€”πŸš€ Comment your answers below! πŸ‘‡

#python #programming #developer #programmer #coding #coder #softwaredeveloper #computerscience #webdev #webdeveloper #webdevelopment #pythonprogramming

https://t.iss.one/DataScienceQ
πŸ‘4❀1
Python Question / Quiz;

What is the output of the following Python code, and why? πŸ€”πŸš€ Comment your answers below! πŸ‘‡

#python #programming #developer #programmer #coding #coder #softwaredeveloper #computerscience #webdev #webdeveloper #webdevelopment #pythonprogramming

https://t.iss.one/DataScienceQ
πŸ‘2❀1
What will be the output of the following code?

import numpy as np
numbers = np.array([1, 2, 3])
new_numbers = numbers + 1
print(new_numbers.tolist())


#python #programming #developer #programmer #coding #coder #softwaredeveloper #computerscience #webdev #webdeveloper #webdevelopment #pythonprogramming

https://t.iss.one/DataScienceQ
πŸ‘2
Python Question / Quiz;

What is the output of the following Python code, and why? πŸ€”πŸš€ Comment your answers below! πŸ‘‡

#python #programming #developer #programmer #coding #coder #softwaredeveloper #computerscience #webdev #webdeveloper #webdevelopment #pythonprogramming #pythonquiz #ai #ml #machinelearning #datascience

https://t.iss.one/DataScienceQ
πŸ‘3
Python Question / Quiz;

What is the output of the following Python code, and why? πŸ€”πŸš€ Comment your answers below! πŸ‘‡

#python #programming #developer #programmer #coding #coder #softwaredeveloper #computerscience #webdev #webdeveloper #webdevelopment #pythonprogramming

https://t.iss.one/DataScienceQ
πŸ‘2
Here are links to the most important free Python courses with a brief description of their value.


1. Coursera: Python for Everybody
Link: https://www.coursera.org/specializations/python
Importance: A perfect starting point for absolute beginners. Covers Python fundamentals and basic data structures, leading to web scraping and database access.

2. freeCodeCamp: Scientific Computing with Python
Link: https://www.freecodecamp.org/learn/scientific-computing-with-python/
Importance: Project-based certification. You build applications like a budget app or a time calculator, reinforcing learning through practical, portfolio-worthy projects.

3. Harvard's CS50P: CS50's Introduction to Programming with Python
Link: https://cs50.harvard.edu/python/2022/
Importance: A rigorous university-level course. Teaches core concepts and problem-solving skills with exceptional depth and clarity, preparing you for complex programming challenges.

4. Real Python Tutorials
Link: https://realpython.com/
Importance: An extensive resource for all levels. Offers in-depth articles, tutorials, and code examples on nearly every Python topic, from basics to advanced specialized libraries.

5. W3Schools Python Tutorial
Link: https://www.w3schools.com/python/
Importance: Excellent for quick reference and interactive learning. Allows you to read a concept and test code directly in the browser, ideal for fast learning and checking syntax.

6. Google's Python Class
Link: https://developers.google.com/edu/python
Importance: A concise, fast-paced course for those with some programming experience. Includes lecture videos and well-designed exercises to quickly get up to speed.

#Python #LearnPython #PythonProgramming #Coding #FreeCourses #PythonForBeginners #Developer #Programming


By: t.iss.one/DataScienceQ πŸš€
❀2πŸ‘1
#How can I implement the K-Nearest Neighbors (KNN) algorithm for classification using scikit-learn? Provide a Python example, explain how distance metrics affect predictions, and discuss the impact of choosing different values of k.

Answer:
KNN is a non-parametric algorithm that classifies data points based on the majority class among their k nearest neighbors in feature space.

import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score, confusion_matrix
import seaborn as sns

# Load dataset
data = datasets.load_iris()
X = data.data
y = data.target
feature_names = data.feature_names
target_names = data.target_names

# Split and scale data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)

# Train KNN model with k=5
knn = KNeighborsClassifier(n_neighbors=5, metric='euclidean')
knn.fit(X_train_scaled, y_train)

# Predict and evaluate
y_pred = knn.predict(X_test_scaled)
accuracy = accuracy_score(y_test, y_pred)
print(f"Accuracy: {accuracy:.2f}")

# Confusion Matrix
cm = confusion_matrix(y_test, y_pred)
plt.figure(figsize=(6, 4))
sns.heatmap(cm, annot=True, fmt='d', cmap='Blues', xticklabels=target_names, yticklabels=target_names)
plt.title('Confusion Matrix')
plt.ylabel('True Label')
plt.xlabel('Predicted Label')
plt.show()

# Visualize decision boundaries (for first two features only)
plt.figure(figsize=(8, 6))
X_plot = X[:, :2] # Use only first two features for visualization
X_plot_scaled = scaler.fit_transform(X_plot)
knn_visual = KNeighborsClassifier(n_neighbors=5)
knn_visual.fit(X_plot_scaled, y)
h = 0.02
x_min, x_max = X_plot_scaled[:, 0].min() - 1, X_plot_scaled[:, 0].max() + 1
y_min, y_max = X_plot_scaled[:, 1].min() - 1, X_plot_scaled[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
Z = knn_visual.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
plt.contourf(xx, yy, Z, alpha=0.3, cmap=plt.cm.Paired)
for i, color in enumerate(['red', 'green', 'blue']):
idx = np.where(y == i)
plt.scatter(X_plot_scaled[idx, 0], X_plot_scaled[idx, 1], c=color, label=target_names[i], edgecolors='k')
plt.xlabel(feature_names[0])
plt.ylabel(feature_names[1])
plt.title('KNN Decision Boundaries (First Two Features)')
plt.legend()
plt.show()


Explanation:
- Distance Metrics: Common choices include Euclidean, Manhattan, and Minkowski. Euclidean is default and suitable for continuous variables.
- Choice of k:
- Small k (e.g., 1 or 3): Sensitive to noise, may overfit.
- Large k: Smoother decision boundaries, but may underfit.
- Optimal k is found via cross-validation.
- Standardization: Crucial because KNN uses distance; unscaled features can dominate results.

Time Complexity: O(nm) per prediction, where n is training samples and m is features.
Space Complexity: O(nm) to store training data.
Use Case: KNN is simple, effective for small-to-medium datasets, and works well when patterns are localized.

#MachineLearning #KNN #Classification #ScikitLearn #DataScience #PythonProgramming #AlgorithmExplained #DimensionalityReduction #SupervisedLearning

By: @DataScienceQ πŸš€
1. What is the output of the following code?
x = [1, 2, 3]
y = x
y.append(4)
print(x)


2. Which of the following data types is immutable in Python?
A) List
B) Dictionary
C) Set
D) Tuple

3. Write a Python program to reverse a string without using built-in functions.

4. What will be printed by this code?
def func(a, b=[]):
b.append(a)
return b

print(func(1))
print(func(2))


5. Explain the difference between == and is operators in Python.

6. How do you handle exceptions in Python? Provide an example.

7. What is the output of:
print(2 ** 3 ** 2)


8. Which keyword is used to define a function in Python?
A) def
B) function
C) func
D) define

9. Write a program to find the factorial of a number using recursion.

10. What does the *args parameter do in a function?

11. What will be the output of:
list1 = [1, 2, 3]
list2 = list1.copy()
list2[0] = 10
print(list1)


12. Explain the concept of list comprehension with an example.

13. What is the purpose of the __init__ method in a Python class?

14. Write a program to check if a given string is a palindrome.

15. What is the output of:
a = [1, 2, 3]
b = a[:]
b[0] = 10
print(a)


16. Describe how Python manages memory (garbage collection).

17. What will be printed by:
x = "hello"
y = "world"
print(x + y)


18. Write a Python program to generate the first n Fibonacci numbers.

19. What is the difference between range() and xrange() in Python 2?

20. What is the use of the lambda function in Python? Give an example.

#PythonQuiz #CodingTest #ProgrammingExam #MultipleChoice #CodeOutput #PythonBasics #InterviewPrep #CodingChallenge #BeginnerPython #TechAssessment #PythonQuestions #SkillCheck #ProgrammingSkills #CodePractice #PythonLearning #MCQ #ShortAnswer #TechnicalTest #PythonSyntax #Algorithm #DataStructures #PythonProgramming

By: @DataScienceQ πŸš€
❀1πŸ‘1
✨🐍 Python Tip: Loop with Index using enumerate! 🐍✨

When you need to iterate through a sequence and also need the index of each item, enumerate() is your best friend! It's more "Pythonic" and cleaner than manually tracking an index.

enumerate() adds a counter to an iterable and returns it as an enumerate object. You can then unpack it directly in your for loop.

my_fruits = ["apple", "banana", "cherry", "date"]

Using enumerate() for a clean loop with index

print("--- Looping with default index ---")
for index, fruit in enumerate(my_fruits):
print(f"Fruit at index {index}: {fruit}")

You can also specify a starting index for the counter

print("\n--- Looping with custom start index (e.g., from 1) ---")
for count, fruit in enumerate(my_fruits, start=1):
print(f"Fruit number {count}: {fruit}")


Output:
--- Looping with default index ---
Fruit at index 0: apple
Fruit at index 1: banana
Fruit at index 2: cherry
Fruit at index 3: date

--- Looping with custom start index (e.g., from 1) ---
Fruit number 1: apple
Fruit number 2: banana
Fruit number 3: cherry
Fruit number 4: date


enumerate() makes your loops more readable and prevents common indexing errors. Give it a try!

#PythonTips #PythonProgramming #LearnPython #Enumerate #CodingHacks

---
By: @DataScienceQ ✨
Python Tip: Mastering init and self in OOP! 🐍

When defining a class in Python, init is a special method (often called the constructor) that gets called automatically every time a new object (instance) of the class is created. It's used to set up the initial state or attributes of that object.

The self parameter is a convention and the first parameter of any instance method. It always refers to the instance of the class itself, allowing you to access its attributes and other methods from within the class.

class Car:
def init(self, make, model, year):
self.make = make # Assign 'make' to the instance's 'make' attribute
self.model = model # Assign 'model' to the instance's 'model' attribute
self.year = year # Assign 'year' to the instance's 'year' attribute

def get_description(self):
return f"This is a {self.year} {self.make} {self.model}."


In the init method, self.make = make means "take the value passed in as make and assign it to the make attribute of this specific Car object."

Let's create some cars:
my_car = Car("Toyota", "Camry", 2020)
your_car = Car("Honda", "Civic", 2022)

print(my_car.get_description())
print(your_car.get_description())


Output:
This is a 2020 Toyota Camry.
This is a 2022 Honda Civic.


init ensures each object starts with its own data, and self connects you to that data!

#PythonTip #OOP #Classes #InitMethod #SelfKeyword #ObjectOriented #PythonProgramming
---
By: @DataScienceQ ✨