March 21, 2026By Shivsharan Kunchalwar

Python and SQL Interview Questions

Python and SQL Interview Questions
G
V
B
+1.5k

Python Interview Questions :     

1. What are Python Decorators?


ANS :

A decorator is a function that modifies the behavior of another function without changing its code.

Decorators are widely used in frameworks like Flask and Django.

Decorators are commonly used for:

  • Logging
  • Authentication
  • Performance measurement


2. What are Generators in Python?

ANS :   

Generators are functions that return an iterator using the yield keyword. Unlike normal functions, they produce values one at a time instead of returning all values at once.


Advantages:

  • Memory efficient
  • Faster execution
  • Useful for large datasets


3.  What is the difference between a deep copy and a shallow copy?

ANS 

Shallow Copy-  Creates a new object but references the same nested objects.

Deep Copy-  Creates a completely independent copy of all objects.


4. What are Python Iterators?

ANS 

An iterator is an object that allows traversal through elements one by one.

Two important methods:

  • __iter__()

  • __next__()


5. What is the difference between == and is?

ANS 

Operator

Meaning

==

                            Compares values

Is 

                            Compares memory location


6.  What are Python Modules?

ANS 

A module is a file containing Python code, such as functions, variables, and classes.


7. What is Exception Handling in Python?

ANS 

Exception handling prevents a program from crashing due to errors.

8. What is Object-Oriented Programming (OOP) in Python?

ANS 

Object-Oriented Programming (OOP) is a programming paradigm that organizes code using objects and classes. In Python, OOP helps developers structure programs in a way that models real-world entities and makes the code modular, reusable, and easy to maintain.


Class → Blueprint or template


Object → Instance of a class


Python supports OOP concepts such as:

Here:

  • Car is a class

  • c1 is an object

  • display() is a method.


Explore Other Demanding Courses

No courses available for the selected domain.

9. What is the __init__() method?

ANS 

__init__() is a constructor used to initialize object attributes when an object is created.


10. What is super() in Python?

ANS 

super() is used to call the parent class constructor or methods.




 SQL Interview Questions 

1. What are Window Functions?

ANS 

Window functions perform calculations across a set of rows.


Common window functions:

  • ROW_NUMBER()

  • RANK()

  • DENSE_RANK()

  • LEAD()

  • LAG()




2. Difference Between RANK() and DENSE_RANK() in SQL

ANS 

RANK() and DENSE_RANK() are window functions used in SQL to assign rankings to rows within a result set based on a specified order. They are commonly used in analytics, reporting, leaderboards, salary rankings, and data analysis.


Both functions are used with the OVER() clause and typically with ORDER BY.

RANK windows function →

RANK() assigns a rank to rows based on the order of values.

If two rows have the same value, they receive the same rank, and the next rank is skipped.

Dense_Rank_function →

DENSE_RANK() also assigns the same rank for duplicate values, but it does NOT skip the next rank.


3. What are the different types of SQL commands?

ANS 

SQL commands are divided into several categories.


Category

Description

DDL

Data Definition Language

DML

Data Manipulation Language

DCL

Data Control Language

TCL

Transaction Control Language


DDL: CREATE, ALTER, DROP


DML: INSERT, UPDATE, DELETE


DCL: GRANT, REVOKE


TCL: COMMIT, ROLLBACK



4. What is a Primary Key?

ANS 

A Primary Key uniquely identifies each record in a table.


5. What is a JOIN in SQL?


A JOIN combines rows from two or more tables based on a related column.

Types of JOIN:

  • INNER JOIN

  • LEFT JOIN

  • RIGHT JOIN

  • FULL JOIN

  • CROSS JOIN


6. What is the difference between WHERE and HAVING?

ANS

WHERE and HAVING are SQL clauses used to filter data in a query. Although they appear similar, they are used at different stages of query execution and serve different purposes.


The key difference is:

  • WHERE filters rows before grouping.

  • HAVING filter groups after aggregation.

Where clause —->

Having Clause →


7. What is a Subquery?

ANS 

A subquery is a query inside another query.


8. What is an Index?


ANS 

An index improves database search performance.

Frequently Asked Questions (FAQs):


1. How many questions are there in a Python interview?

Fundamental subjects include data types, OOP concepts, functions, exception handling, and libraries like NumPy or Pandas.


2. KINDLY DO TELL US MORE ABOUT OUR CODING QUESTIONS IN A PYTHON INTERVIEW?

Yes, there are coding problems in most interviews to test logic and problem-solving while testing the concepts of Python syntax.


3. So, an immutable object is being used to create a tuple.

Lists, by contrast, are mutable, and tuples are generally faster and consume less memory.


4. What are a few ways to effectively prepare for a Python interview?

This means practicing coding problems, revising your basics, getting knowledge about projects, and understanding common interview questions.


5. Are real-world problems asked during Python interviews?

Yes, a lot of interviews include practical problems or case studies to test the application of concepts.


Related Links:

Top 100 Python Interview Questions and Answers

Joins in SQL



Do visit our channel to know more: SevenMentor

Author:-

Shivsharan Kunchalwar


Shivsharan Kunchalwar

Expert trainer and consultant at SevenMentor with years of industry experience. Passionate about sharing knowledge and empowering the next generation of tech leaders.

#Technology#Education#Career Guidance

Call the Trainer and Book your free demo Class..... Call now!!!

| SevenMentor Pvt Ltd.

© Copyright 2025 | SevenMentor Pvt Ltd.