MLStackMLSCCafé
 
 
Sign in with GoogleSign in with Google. Opens in new tab
Master Your ML & AIAI Interview
2103 Curated Machine Learning, Data Science, AI & LLMs Interview Questions
Answered To Get Your Next Six-Figure Job Offer
👨‍💻 Having Full-Stack & Coding Interview? Check  FullStack.Cafe - 3877 Full-Stack, Coding & System Design Questions and AnswersHaving Full-Stack & Coding Interview? Check 👨‍💻 FullStack.Cafe - 3877 Full-Stack, Coding & System Design Questions and Answers

Top 139 Python Interview Questions

Entry Junior Mid Senior Expert
Sign in with GoogleSign in with Google. Opens in new tab
Learning Progress:

Python Theoretical Questions

Q1:   

Name some characteristics of Python?

  
Add to PDF   Entry 
Q2:   

What are the built-in types available In Python?

  
Add to PDF   Entry 
Q3:   

How do I modify a string?

  
Add to PDF   Entry 
Q4:   

What are the rules for local and global variables in Python?

  
Add to PDF   Junior 
Q5:   

What are local variables and global variables in Python?

  
Add to PDF   Junior 
Q6:   

What is Negative Index in Python?

  
Add to PDF   Junior 
Q7:   

What are descriptors?

  
Add to PDF   Junior 
Q8:   

Name some benefits of Python

  
Add to PDF   Junior 
Q9:   

When to use a tuple vs list vs dictionary in Python?

  
Add to PDF   Junior 
Q10:   

What is Lambda Functions in Python?

  
Add to PDF   Junior 
Q11:   

Explain what is Linear (Sequential) Search and when may we use one?

 JSPY Related To: Searching
Add to PDF   Junior 
Q12:   

Explain what is Binary Search

 JSJavaPY Related To: Searching
Add to PDF   Junior 
Q13:   

Does Python have a switch-case statement?

  
Add to PDF   Junior 
Q14:   

How the string does get converted to a number?

  
Add to PDF   Junior 
Q15:   

What is the function of self?

  
 Add to PDF   Mid 
Q16:   

What does the Python nonlocal statement do (in Python 3.0 and later)?

  
 Add to PDF   Mid 
Q17:   

What is introspection/reflection and does Python support it?

  
 Add to PDF   Mid 
Q18:   

Explain how to use Slicing in Python?

  
 Add to PDF   Mid 
Q19:   

How can I create a copy of an object in Python?

  
 Add to PDF   Mid 
Q20:   

How can you share global variables across modules?

  
 Add to PDF   Mid 
Q21:   

What is the difference between range and xrange? How has this changed over time?

  
 Add to PDF   Mid 
Q22:   

What are the Wheels and Eggs? What is the difference?

  
 Add to PDF   Mid 
Q23:   

What are the key differences between Python 2 and 3?

  
 Add to PDF   Mid 
Q24:   

What is a Callable?

  
 Add to PDF   Mid 
Q25:   

What is a Jump (or Block) Search?

 JSJavaPY Related To: Searching
 Add to PDF   Mid 
Q26:   

What are the Dunder/Magic/Special methods in Python? Name a few.

  
 Add to PDF   Mid 
Q27:   

What does an x = y or z assignment do in Python?

  
 Add to PDF   Mid 
Q28:   

Explain what is Interpolation Search

 JSPY Related To: Searching
 Add to PDF   Mid 
Q29:   

What are virtualenvs?

  
 Add to PDF   Mid 
Q30:   

What is the python with statement designed for?

  
 Add to PDF   Mid 
Q31:   

What are the advantages of R in comparison with Python?

  Related To: R
 Add to PDF   Mid 
Q32:   

In which cases would you use Python over R and vice versa?

  Related To: R
 Add to PDF   Mid 
Q33:   

What's the difference between lists and tuples?

  
 Add to PDF   Mid 
Q34:   

Is it possible to have static methods in Python?

  
 Add to PDF   Mid 
Q35:   

What are the disadvantages of R in comparison with Python?

  Related To: R
 Add to PDF   Mid 
Q36:   

Explain how does Python memory management work?

  
 Add to PDF   Mid 
Q37:   

What's the difference between the list methods append() and extend()?

  
 Add to PDF   Mid 
Q38:   

What is the purpose of meshgrid in Python/NumPy?

  Related To: NumPy
 Add to PDF   Mid 
Q39:   

Why would you use the pass statement?

  
 Add to PDF   Mid 
Q40:   

What are Decorators in Python?

  
 Add to PDF   Mid 
Q41:   

What are immutable objects in Python?

  
 Add to PDF   Mid 
Q42:   

What does this stuff mean: *args, **kwargs? Why would we use it?

  
 Add to PDF   Mid 
Q43:   

What is Pickling and Unpickling?

  
 Add to PDF   Mid 
Q44:   

What is a None value?

  
 Add to PDF   Mid 
Q45:   

How to determine k using the Elbow Method?

 PY Related To: K-Means Clustering
 Add to PDF   Mid 
Q46:   

What is the difference between range and xrange functions in Python?

  
 Add to PDF   Mid 
Q47:   

Explain the UnboundLocalError exception and how to avoid it?

  
 Add to PDF   Mid 
Q48:   

What is Monkey Patching and is it ever a good idea?

  
 Add to PDF   Mid 
Q49:   

How would you create a Recommender System for Text Inputs?

 PY Related To: Recommendation Systems
 Add to PDF   Mid 
Q50:   

Is there a tool to help find bugs or perform static analysis?

  
 Add to PDF   Mid 
Q51:   

What is MRO in Python? How does it work?

  
 Add to PDF   Senior 
Q52:   

Explain how you reverse a generator?

  
 Add to PDF   Senior 
Q53:   

What is the difference between deep and shallow copy?

  
 Add to PDF   Senior 
Q54:   

What is Monkey Patching? How to use it in Python?

  
 Add to PDF   Senior 
Q55:   

What are the advantages of NumPy over regular Python lists?

  
 Add to PDF   Senior 
Q56:   

Why aren't Python nested functions called closures?

  
 Add to PDF   Senior 
Q57:   

What is the difference between a function decorated with @staticmethod and one decorated with @classmethod?

  
 Add to PDF   Senior 
Q58:   

How is Differential Evolution different from Genetic Algorithms?

 PY Related To: Genetic Algorithms
 Add to PDF   Senior 
Q59:   

How to determine k using the Silhouette Method?

 PY Related To: K-Means Clustering
 Add to PDF   Senior 
Q60:   

How to work with transitive dependencies?

  
 Add to PDF   Senior 
Q61:   

What are metaclasses in Python?

  
 Add to PDF   Senior 
Q62:   

What's the difference between a Python module and a Python package?

  
 Add to PDF   Senior 
Q63:   

What is the difference between @staticmethod and @classmethod?

  
 Add to PDF   Senior 
Q64:   

Why are default values shared between objects?

  
 Add to PDF   Senior 
Q65:   

What is GIL?

  
 Add to PDF   Senior 
Q66:   

Is it a good idea to use multi-thread to speed your Python code?

  
 Add to PDF   Senior 
Q67:   

Why Python (CPython and others) uses the GIL?

  
 Add to PDF   Senior 
Q68:   

What is the difference between old style and new style classes in Python?

  
 Add to PDF   Senior 
Q69:   

How is set() implemented internally?

  
 Add to PDF   Senior 
Q70:   

Can you explain Closures (as they relate to Python)?

  
 Add to PDF   Senior 
Q71:   

What is an alternative to GIL?

  
 Add to PDF   Senior 
Q72:   

How is memory managed in Python?

  
 Add to PDF   Senior 
Q73:   

What is the purpose of the single underscore _ variable in Python?

  
 Add to PDF   Senior 
Q74:   

What is Cython?

  
 Add to PDF   Senior 
Q75:   

Why are Python's private methods not actually private?

  
 Add to PDF   Senior 
Q76:   

Why would you use metaclasses?

  
 Add to PDF   Expert 
Q77:   

How to train a network only on one output when there are multiple outputs in Keras?

  Related To: Keras
 Add to PDF   Expert 
Q78:   

Describe Python's Garbage Collection mechanism in brief

  
 Add to PDF   Expert 
Q79:   

Is there a simple, elegant way to define singletons?

  
 Add to PDF   Expert 
Q80:   

Why use else in try/except construct in Python?

  
 Add to PDF   Expert 
Q81:   

What is a global interpreter lock (GIL) and why is it an issue?

  
 Add to PDF   Expert 
Q82:   

Is there any downside to the -O flag apart from missing on the built-in debugging information?

  
 Add to PDF   Expert 
Q83:   

What does Python optimisation (-O or PYTHONOPTIMIZE) do?

  
 Add to PDF   Expert 
Q84:   

Why isn't all memory freed when Python exits?

  
 Add to PDF   Expert 

Python Practical Challenges

Q1:   

Explain how Bubble Sort works

 JSPY Related To: Sorting
 Add to PDF   Entry 
Q2:   

Explain how Insertion Sort works

 JSJavaPY Related To: Sorting
 Add to PDF   Junior 
Q3:   

How to find all occurrences of an Element in a list

  Related To: NumPy
 Add to PDF   Junior 
Q4:   

Return the N-th value of the Fibonacci sequence. Solve in O(n) time

 JSJavaPY Related To: Fibonacci Series, Data Structures
 Add to PDF   Junior 
Q5:   

Given variables a and b, switch their values so that b has the value of a, and a has the value of b without using an intermediary variable

  
 Add to PDF   Junior 
Q6:   

How to implement a Tree data-structure? Provide some code.

 JavaPY Related To: Binary Tree, Trees, Data Structures
 Add to PDF   Junior 
Q7:   

Return the N-th value of the Fibonacci sequence Recursively

 JSJavaPY Related To: Fibonacci Series, Data Structures
 Add to PDF   Junior 
Q8:   

Convert a Singly Linked List to Circular Linked List

 PY Related To: Linked Lists, Data Structures
 Add to PDF   Junior 
Q9:   

Suppose lst is [2, 33, 222, 14, 25]. What is lst[-1]?

  
 Add to PDF   Junior 
Q10:   

Implement Pre-order Traversal of Binary Tree using Recursion

 JavaPY Related To: Binary Tree, Data Structures
 Add to PDF   Junior 
Q11:   

Is this valid in Python and why?

  
  Add to PDF   Mid 
Q12:   

Sort a Stack using another Stack

 JavaPY Related To: Stacks, Sorting
  Add to PDF   Mid 
Q13:   

What is the most efficient way to concatenate many strings together?

  
  Add to PDF   Mid 
Q14:   

Sort a Stack using Recursion

 JavaPY Related To: Stacks, Sorting
  Add to PDF   Mid 
Q15:   

Write a program to check whether the object is of a class or its subclass

  
  Add to PDF   Mid 
Q16:   

Explain how Merge Sort works

 JSPY Related To: Divide & Conquer, Sorting
  Add to PDF   Mid 
Q17:   

Explain how does the Sentinel Search work?

 CSPY Related To: Searching
  Add to PDF   Mid 
Q18:   

After executing the above code, what is the value of y?

  
  Add to PDF   Mid 
Q19:   

Write a program for Recursive Binary Search

 JSJavaPY Related To: Searching
  Add to PDF   Mid 
Q20:   

How to make a flat list out of list of lists?

  
  Add to PDF   Mid 
Q21:   

Can you do Iterative Pre-order Traversal of a Binary Tree without Recursion?

 CSPY Related To: Binary Tree, Data Structures
  Add to PDF   Mid 
Q22:   

Convert a Binary Tree to a Doubly Linked List

 JavaPY Related To: Binary Tree, Divide & Conquer, Linked Lists, Recursion, Data Structures
  Add to PDF   Mid 
Q23:   

Find all the Permutations of a String

 JSJavaPY Related To: Backtracking, Strings, Data Structures
  Add to PDF   Mid 
Q24:   

How do I check if a list is empty?

  
  Add to PDF   Mid 
Q25:   

How to check if two Strings (words) are Anagrams?

 CSJavaPY Related To: Strings, Data Structures
  Add to PDF   Mid 
Q26:   

How to merge two sorted Arrays into a Sorted Array?

 JSJavaPY Related To: Arrays, Data Structures
  Add to PDF   Mid 
Q27:   

Explain how Heap Sort works

 JSPY Related To: Heaps and Maps, Sorting, Data Structures
  Add to PDF   Mid 
Q28:   

What does the Lambda layer do in Keras? What would be the output of this model?

  Related To: Keras
  Add to PDF   Mid 
Q29:   

LIS: Find length of the longest increasing subsequence (LIS) in the array. Solve using DP.

 JSJavaPY Related To: Dynamic Programming, Data Structures
  Add to PDF   Mid 
Q30:   

What will be the output of the code below?

  
  Add to PDF   Senior 
Q31:   

Explain when and how to use Exponential (aka Doubling or Galloping) Search?

 JSPY Related To: Searching
  Add to PDF   Senior 
Q32:   

Explain how would you train Perceptron? Implement in plain Python

 PY Related To: Neural Networks
  Add to PDF   Senior 
Q33:   

Implement K-Means Clustering Algorithm in plain Python

 PY Related To: K-Means Clustering
  Add to PDF   Senior 
Q34:   

Explain how Radix Sort works

 JSPY Related To: Sorting
  Add to PDF   Senior 
Q35:   

Implement k-Nearest-Neighbor Algorithm in plain Python

 PY Related To: K-Nearest Neighbors
  Add to PDF   Senior 
Q36:   

How would you train Logistic Regression? Implement in Python

 PY Related To: Logistic Regression
  Add to PDF   Senior 
Q37:   

How would you train Linear Regression model using Gradient Descent? Implement in Python

 PY Related To: Gradient Descent, Linear Regression
  Add to PDF   Senior 
Q38:   

How would you train Linear Regression model using Normal Equation? Implement in Python

 PY Related To: Linear Regression
  Add to PDF   Senior 
Q39:   

How do I write a function with output parameters (call by reference)

  
  Add to PDF   Senior 
Q40:   

Create function that similar to os.walk

  
  Add to PDF   Senior 
Q41:   

What will be returned by this code?

  
  Add to PDF   Senior 
Q42:   

Whenever you exit Python, is all memory de-allocated?

  
  Add to PDF   Senior 
Q43:   

Show me three different ways of fetching every third item in the list

  
  Add to PDF   Senior 
Q44:   

How to make a chain of function decorators?

  
  Add to PDF   Senior 
Q45:   

Find the length of a Linked List which contains Cycle (Loop)

 JavaPY Related To: Linked Lists, Data Structures
  Add to PDF   Senior 
Q46:   

Will the code below work? Why or why not?

  
  Add to PDF   Senior 
Q47:   

Explain what is Fibonacci Search technique?

 CSJSJavaPY Related To: Divide & Conquer, Fibonacci Series, Searching, Data Structures
  Add to PDF   Senior 
Q48:   

Binet's formula: How to calculate Fibonacci numbers without Recursion or Iteration?

 CSJSJavaPY Related To: Fibonacci Series, Data Structures
  Add to PDF   Senior 
Q49:   

Explain how QuickSort works

 JSPY Related To: Divide & Conquer, Sorting, Data Structures
  Add to PDF   Senior 
Q50:   

How to read a 8GB file in Python?

  
  Add to PDF   Expert 
Q51:   

Explain how you would implement CART training algorithm in plain Python

 PY Related To: Decision Trees
  Add to PDF   Expert 
Q52:   

How would you implement primal SVM in plain Python?

 PY Related To: SVM
  Add to PDF   Expert 
Q53:   

What will this code return?

  
  Add to PDF   Expert 
Q54:   

How do I access a module written in Python from C?

  
  Add to PDF   Expert 
Q55:   

How should one access nonlocal variables in closures in python 2.x?

  
  Add to PDF   Expert 
 

Prepare for AI developer and engineer interviews with 19 answered OpenClaw questions covering Gateway architecture, channels, agent workspaces, memory, MCP, model failover, multi-agent routing, security, sandboxing, approvals, and remote operations....

Prepare for AI agent developer interviews with 15 Model Context Protocol (MCP) questions covering tools, resources, prompts, JSON-RPC, transports, roots, sampling, security, and practical MCP server design....

Amazone runs the internet as we know it. Amazon Web Services (AWS) offers a comprehensive suite of machine learning (ML) services that cater to various needs and expertise levels. Follow along and learn the 23 most common AWS machine-learning intervi...

Azure Machine Learning (Azure ML) is a cloud-based service for creating and managing machine learning solutions. It’s designed to scale, distribute, and deploy machine learning models to the cloud. Follow along and learn the 23 most common Azure Mach...
Hadoop is an open-source big data processing framework. It leverages distributed computing to store and process large datasets in a fault-tolerant manner. According to recent reports, Apache Hadoop is one of the most sought-after big data skills with...
Apache Spark is a unified analytics engine for large-scale data processing. It is built to handle various use cases in big data analytics, including data processing, machine learning, and graph processing. Follow along and learn the 23 most common an...
Scala is a powerful language with functional programming capabilities that can be a good choice for data science, especially in big data and distributed computing scenarios. As an example, Apache Spark, a popular distributed data processing framework...
PyTorch popularity as a Deep Learning framework of choice is on the rise. As of December 2022, 62% of the academic papers were implemented in PyTorch whereas only 4% were for TensorFlow. Follow along and prepare effectively with these key 30 PyTorch ...
The use of Artificial Intelligence (AI) in machine learning and data science enabled advancements in areas such as natural language processing, computer vision, recommendation systems, fraud detection, predictive analytics, and personalized medicine....
Optimization algorithms are extensively used in training machine learning models. Data engineers employ algorithms like gradient descent, stochastic gradient descent, and variants (e.g., Adam, RMSprop) to optimize the model parameters and minimize th...