HomeInterview QuestionsPython Interview Questions

Python Interview Questions

103 real Python questions asked in live technical interviews — each with a model answer. Updated weekly.

🎤 Auto-captured by Assisting AI during live interviews

These Python interview questions were captured from real interviews by candidates using Assisting AI. Each links to a full model answer. For real-time help during your own interview, get Assisting AI from ₹500/day.

I am asking about Python generators. How do you use them? For example, how does the yield statement work?🟢 Easy · Conceptual · Asked 20×What is a Python palindrome?🟢 Easy · Conceptual · Asked 6×Can you add values from both these lists?🟡 Medium · Coding · Asked 4×Can you define two lambda functions? Also, define two lists with four elements each.🟢 Easy · Coding · Asked 4×Write code to check if a list is a palindrome.🟢 Easy · Coding · Asked 3×I'm getting an indentation error. How can I fix it?🟢 Easy · Debugging · Asked 2×Write a Python script that lists all files under a given directory path.🟢 Easy · Coding · Asked 1×How can you remove duplicate values from a list?🟢 Easy · Coding · Asked 1×What are the collection types we have in Python?🟢 Easy · Conceptual · Asked 1×Write a Python function to reverse a string.🟢 Easy · Coding · Asked 1×Find the most occurring element and its frequency in an array.🟡 Medium · Coding · Asked 1×Can you explain the difference between Python, List, and Tuple?🟢 Easy · Conceptual · Asked 1×Given two pandas DataFrames, df_employee and df_department, write code to join them on the employee ID, select the default columns, and write the resulting DataFrame back to a file.🟢 Easy · Coding · Asked 1×Write Python logic to count word frequency in a string.🟡 Medium · Coding · Asked 1×Write Python code to count word frequency in a string.🟢 Easy · Coding · Asked 1×What are Python generators and how are they used?🟢 Easy · Conceptual · Asked 1×What is the difference between remove, pop, and del in Python?🟢 Easy · Conceptual · Asked 1×What are the differences between a list, a set, and a dictionary?🟡 Medium · Conceptual · Asked 1×What are *args and **kwargs in Python?🟢 Easy · Conceptual · Asked 1×What is the difference between a shallow copy and a deep copy in Python?🟡 Medium · Conceptual · Asked 1×What is the difference between a decorator and a regular function in Python?🟡 Medium · Conceptual · Asked 1×What is the difference between 'and' and 'is' in Python?🟢 Easy · Conceptual · Asked 1×What are *args and **kwargs in Python, and how do they differ from a deep copy?🟢 Easy · Conceptual · Asked 1×What is the difference between a list and a tuple in Python? What is the difference between == and is in Python? What are Python decorators?🟡 Medium · Conceptual · Asked 1×What is the difference between a list and a tuple in Python?🟢 Easy · Conceptual · Asked 1×Move all zeros to the end of a list of numbers.🟡 Medium · Coding · Asked 1×Given an array containing special characters, numbers, lowercase letters, and uppercase letters, write Python code to sort it so that special characters come first, followed by numbers, then lowercase letters, and finally uppercase letters.🟡 Medium · Coding · Asked 1×How can you execute a function as soon as a class is instantiated?🟢 Easy · Coding · Asked 1×What API integrations have you done? Which ones did you use Python for, and any other languages?🟡 Medium · Conceptual · Asked 1×What are decorators and why do we need to use them?🟢 Easy · Conceptual · Asked 1×Have you worked with generators and decorators? Which functions have you used?🟡 Medium · Conceptual · Asked 1×Why do we need pandas? We have SQL and PySpark. Why use pandas?🟢 Easy · Conceptual · Asked 1×What other Python modules have you used?🟢 Easy · Other · Asked 1×Have you used pandas?🟢 Easy · Behavioral · Asked 1×Write a Python program that takes an array of six elements and prints the count of even and odd numbers present.🟢 Easy · Coding · Asked 1×How can I identify duplicate rows in a dataset without dropping them, and display the count of duplicates for each employee ID (e.g., employee ID 1, John, is duplicated)?🟡 Medium · Coding · Asked 1×Explain generators and iterators and when they should be used.🟡 Medium · Conceptual · Asked 1×Explain how to implement exception handling and logging in production‑grade Python applications.🟡 Medium · Conceptual · Asked 1×Explain the difference between multithreading and multiprocessing in Python.🟡 Medium · Conceptual · Asked 1×On a scale of 1 to 10, how would you rate your proficiency in Python?🟢 Easy · Behavioral · Asked 1×Have you heard of method resolution order (MRO) in Python?🟢 Easy · Conceptual · Asked 1×Are you familiar with method resolution order (MRO) in Python?🟢 Easy · Conceptual · Asked 1×Are you familiar with Git, Jenkins, dbt, typical CI/CD pipelines, and Python, and how to deploy objects from development to production?🟡 Medium · Conceptual · Asked 1×I have experience working with Python. Can you explain the configuration steps required to onboard new Oracle tables and ingest them into Snowflake using Python? What considerations are there for the source and target configurations?🟡 Medium · Conceptual · Asked 1×Rate yourself in Python on a scale of one to five.🟢 Easy · Behavioral · Asked 1×Do you have experience in Python?🟢 Easy · Behavioral · Asked 1×Do you have experience in PySpark?🟢 Easy · Behavioral · Asked 1×Did you use Python to build automation first?🟢 Easy · Conceptual · Asked 1×Do we need PySpark experience for a project that involves automation, leveraging Python automation libraries, working with APIs to connect to various systems, and developing an automation framework?🟡 Medium · Conceptual · Asked 1×Between Python and PySpark on Databricks, which is more professional? If you had to choose a primary skill set, what would you pick?🟡 Medium · Conceptual · Asked 1×Which Python libraries will you use for processing?🟡 Medium · Conceptual · Asked 1×Suppose you have a lot of files in a folder in an S3 bucket and want to move all files into a B folder. How would you do that?🟡 Medium · Coding · Asked 1×How do you flatten a nested list in Python to bring all elements into the outermost list?🟡 Medium · Coding · Asked 1×Do you have experience writing Python and SQL?🟢 Easy · Other · Asked 1×How would you test an application, such as a Spark or Python application, for a project?🟡 Medium · Conceptual · Asked 1×Write code to sort list L1 and reorder list L2 so that each element in L2 stays paired with its corresponding element in L1 after sorting.🟡 Medium · Coding · Asked 1×A new file is stored in one location. Write a code snippet that moves it to a different target location.🟢 Easy · Coding · Asked 1×You have an input CSV file in a source location. Read the file, drop an existing column, and add a new derived column that increases the salary by three times. Provide a code snippet.🟡 Medium · Coding · Asked 1×Can you explain a little bit about Python? Have you written complex code using Python as a scripting language?🟢 Easy · Conceptual · Asked 1×Let's talk about Python. What Python libraries have you used?🟢 Easy · Conceptual · Asked 1×I wrote the line `response = request.get(API_URL)`. What is wrong with this?🟢 Easy · Debugging · Asked 1×How do you call a REST API, gather the response, and then read a CSV into a pandas DataFrame?🟡 Medium · Coding · Asked 1×Write a Python code block that calls a REST API endpoint, receives a JSON response, and uploads a file to an S3 bucket.🟡 Medium · Coding · Asked 1×Have you used any built-in operators in Python during development?🟢 Easy · Conceptual · Asked 1×Given a list of records with amounts and currencies, convert all USD amounts to EUR and add the converted amounts to each record.🟡 Medium · Coding · Asked 1×Given the string `text = "python is easy and python is powerful"`, count the words and store the counts in a dictionary using Python.🟢 Easy · Coding · Asked 1×Count how many times each word appears and store the result in a dictionary.🟡 Medium · Coding · Asked 1×Given the text `python is easy and python is powerful`, write code to count the frequency of each word.🟢 Easy · Coding · Asked 1×Count the frequency of each character in the string and output the result as a dictionary.🟢 Easy · Coding · Asked 1×Explain a complex Python PySpark code you have created in either your current or past projects. First describe the business problem, then explain the code you wrote to solve it.🟡 Medium · Behavioral · Asked 1×Can you give a brief overview of Python's SQL capabilities?🟢 Easy · Conceptual · Asked 1×What are the key differences between constructors and decorators in Python?🟢 Easy · Conceptual · Asked 1×One last question: how do you pass complex strings to functions in native Python?🟡 Medium · Conceptual · Asked 1×Can you write examples in Python?🟢 Easy · Coding · Asked 1×Do you have the chance to write any code in Python?🟢 Easy · Conceptual · Asked 1×What do you know about basic Python?🟢 Easy · Conceptual · Asked 1×Have you used decorators in Python? What is their use?🟡 Medium · Conceptual · Asked 1×What is the output of the following Python code and why?🟡 Medium · Conceptual · Asked 1×What issues are present in the following Python code?🟡 Medium · Debugging · Asked 1×Write a simple Python calculator function that can add, subtract, multiply, and divide two numbers. Provide the complete code and show how to call it.🟢 Easy · Coding · Asked 1×What will be the output of the following Python code? ```python def add_to_inventory(item, inventory=[]): inventory.append(item) return inventory print(add_to_inventory('apple')) print(add_to_inventory('banana')) ``` Also explain why this behavior occurs.🟡 Medium · Conceptual · Asked 1×What is the issue with the following code? ```python def add_to_inventory(item, inventory=[]): inventory.append(item) return inventory print(add_to_inventory("apple")) print(add_to_inventory("banana")) ```🟡 Medium · Conceptual · Asked 1×Does Python compile or interpret code, and how does it run?🟢 Easy · Conceptual · Asked 1×Why is Spark faster than normal Python computations?🟡 Medium · Conceptual · Asked 1×Can we run automatic operations in Python? Why don't we do that? Why use Path? Even distributed tasks can be done using Python, so why use Path at all?🟡 Medium · Conceptual · Asked 1×Why do we need to use Spark? Why can't we directly perform computations using Python itself?🟡 Medium · Conceptual · Asked 1×You must call a rate‑limited partner API to enrich records before writing to Silver. The goal is high throughput with bounded concurrency and retries. What Python pattern fits best?🟡 Medium · Conceptual · Asked 1×I created a Lambda function that calls another Lambda function and added some Python libraries. When I try to import those libraries, some are not available. How can I resolve this?🟡 Medium · Debugging · Asked 1×In your primary skills, which languages do you use—Python, SQL, PySpark, AWS—and how would you rate yourself out of 10?🟢 Easy · Behavioral · Asked 1×Do you understand the tech stack? You have experience with Python, SQL, PySpark, and AWS. Is there anything else you'd like to add?🟢 Easy · Conceptual · Asked 1×I have a list with some values. I have a variable called 'five' which is 5. I want to look through the list for the value of 'five', get its index, and print it if present, otherwise print that it's not present. Any questions?🟢 Easy · Coding · Asked 1×How do you initialize a list and add random values to it?🟢 Easy · Coding · Asked 1×Write a Python compiler.🔴 Hard · Coding · Asked 1×Once I have found that the code is taking a long time, what strategies would I use to reduce the runtime?🟡 Medium · Conceptual · Asked 1×Will time complexity matter when finding a solution in a thousand lines of code? How can I determine the time complexity?🟡 Medium · Conceptual · Asked 1×What is Python used for?🟢 Easy · Conceptual · Asked 1×How do you implement fault tolerance using try-except blocks in code?🟢 Easy · Conceptual · Asked 1×Write Python Django code to create an API that fetches a value from a query parameter and inserts this value into a database.🟡 Medium · Coding · Asked 1×What is an iterator in Python?🟢 Easy · Conceptual · Asked 1×What will be the output of the following Python code and why?🟡 Medium · Conceptual · Asked 1×How do you create a DataFrame with a column named 'current_amount'?🟢 Easy · Coding · Asked 1×Given the list list1 = [1, 2, 2, 3, 1, 4, 2, 3], find the frequency of each element without using existing functions.🟢 Easy · Coding · Asked 1×Given the dictionary ab = {'b':2,'a':3,'c':1}, sort it by values to obtain {'c':1,'b':2,'a':3} and by keys to obtain {'a':3,'b':2,'c':1}.🟢 Easy · Coding · Asked 1×

🎤 Get Python questions answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.

Get Assisting AI — Starts at ₹500

Browse Other Topics