0% found this document useful (0 votes)
13 views3 pages

Python and SQL Interview Questions

Uploaded by

krishnakrisha001
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Python and SQL Interview Questions

Uploaded by

krishnakrisha001
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Python:
o Question: What is the difference between a list and a tuple in Python?
 A) Lists are mutable, while tuples are immutable.
 B) Tuples are ordered, while lists are not.
 C) Lists can contain elements of different data types, while tuples
cannot.
 D) Tuples can be resized, while lists cannot.
 Answer: A) Lists are mutable, while tuples are immutable.

2. Python:
o Question: How do you open a file in Python for reading?
 A) file = open("[Link]", "w")
 B) file = open("[Link]", "r")
 C) file = open("[Link]", "a")
 D) file = open("[Link]", "x")
 Answer: B) file = open("[Link]", "r")
3. SQL:
o Question: What is the purpose of the GROUP BY clause in SQL?
 A) To sort the result set in ascending order.
 B) To filter rows based on a condition.
 C) To group rows with similar values into summary rows.
 D) To join two or more tables.
 Answer: C) To group rows with similar values into summary rows.
4. Python:
o Question: How do you remove an element from a list in Python?
 A) [Link](item)
 B) [Link](index)
 C) del list[index]
 D) All of the above
 Answer: D) All of the above
5. SQL:
o Question: What is the difference between INNER JOIN and LEFT JOIN?
 A) INNER JOIN returns all rows from both tables, while LEFT JOIN
returns only matching rows.
 B) INNER JOIN returns only matching rows, while LEFT JOIN
returns all rows from both tables.
 C) INNER JOIN is used for self-joins, while LEFT JOIN is used for
joining different tables.
 D) There is no difference; they are interchangeable.
 Answer: A) INNER JOIN returns all rows from both tables, while
LEFT JOIN returns only matching rows.
6. SQL:
o Question: What is a subquery in SQL?
 A) A query that runs in parallel with the main query.
 B) A query that returns a single value.
 C) A query nested inside another query.
 D) A query that joins multiple tables.
 Answer: C) A query nested inside another query.
7. Python:
o Question: How do you reverse a list in Python?
 A) [Link]()
 B) reversed(list)
 C) list[::-1]
 D) All of the above
 Answer: D) All of the above

Certainly! Here are 10 more intermediate-level interview questions related to Python and
SQL, along with 4 multiple-choice options for each question:
[Link]:

o Question: What is the purpose of the enumerate() function in Python?


 A) To iterate over a sequence while keeping track of the index.
 B) To create an enumerated list.
 C) To find the maximum value in a list.
 D) To reverse the order of elements in a list.
 Answer: A) To iterate over a sequence while keeping track of the
index.
2. SQL:
o Question: What is a self-join in SQL?
 A) A join between two different tables.
 B) A join where the same table is used twice.
 C) A join that includes an aggregate function.
 D) A join that involves subqueries.
 Answer: B) A join where the same table is used twice.
3. Python:
o Question: How do you handle exceptions in Python using
a try and except block?
 A) try { ... } catch { ... }
 B) try: ... except: ...
 C) try except { ... }
 D) try: ... catch: ...
 Answer: B) try: ... except: ...
4. SQL:
o Question: What is the purpose of the HAVING clause in SQL?
 A) To filter rows based on a condition.
 B) To sort the result set.
 C) To group rows by a specific column.
 D) To filter aggregated data.
 Answer: D) To filter aggregated data.
5. SQL:
o Question: What is the difference between a primary key and a unique key in a
database table?
 A) Both keys enforce uniqueness, but a primary key can be NULL
while a unique key cannot.
 B) A primary key is used for sorting, while a unique key is not.
 C) A unique key can have multiple columns, while a primary key
cannot.
 D) There is no difference; they are interchangeable.
 Answer: A) Both keys enforce uniqueness, but a primary key can be
NULL while a unique key cannot.
6. Python:
o Question: How do you sort a list of dictionaries based on a specific key?
 A) sorted(list_of_dicts, key=lambda x: x['key'])
 B) list_of_dicts.sort(key='key')
 C) list_of_dicts.sort(key=lambda x: x['key'])
 D) sorted(list_of_dicts, key='key')
 Answer: A) sorted(list_of_dicts, key=lambda x: x['key'])

7. SQL:
o Question: What is the purpose of the LIKE operator in SQL?
 A) To perform arithmetic operations.
 B) To filter rows based on exact matches.
 C) To search for patterns in string columns.
 D) To join tables.
 Answer: C) To search for patterns in string columns.

8. Python:
o Question: What is the use of a service account?
 A) used to run individual jobs
 B) used to run all application jobs
 C) used to kill any individual jobs
 D) All the above
 Answer: A) [Link]()

Common questions

Powered by AI

Primary keys differ from unique keys primarily in that a primary key is a minimal set of columns used to uniquely identify each row in a table, and it cannot contain NULL values. Unique keys also enforce uniqueness but can include NULL values. This distinction affects data integrity, as primary keys ensure that no two rows can be identical, while unique keys allow for some flexibility, such as optional data, which can be useful in secondary identification needs .

A service account in Python applications is typically used to automate tasks and interact securely with APIs, providing authentication without user intervention. It aids in running background services or cron jobs that need access to resources on behalf of applications rather than individual users. This approach enhances security by minimizing the exposure of user credentials and optimizing resource access in server-side or cloud applications .

INNER JOIN in SQL returns only rows that have matching values in both joined tables, which is useful when only matched data is needed. LEFT JOIN, on the other hand, returns all rows from the left table and the matched rows from the right table, or NULL for non-matched rows, making it preferable in scenarios where retaining all records from the primary (left) table is crucial, such as generating reports where missing data needs highlighting .

A subquery, or a nested query, is an SQL query embedded within another SQL query, often within the WHERE or SELECT clause. It allows for more complex querying operations like filtering results of a larger query based on the criteria defined in the subquery. Subqueries can enhance performance by making the main query simpler and more readable, and in some cases, they can be optimized by the database engine to reduce execution time .

The enumerate() function in Python allows iteration over a sequence while keeping track of the index of each element. This can be particularly advantageous when you need both the index and the item in loops, as it enhances readability and efficiency by returning tuples containing the index and element, eliminating the need for manually managing a counter . This functionality is especially beneficial in scenarios where the index is used for additional processing or logging.

The HAVING clause in SQL allows for filtering of grouped data after aggregation, unlike the WHERE clause which filters rows before aggregation. This distinction is critical when working with grouped records, as HAVING enables the filtering based on aggregate functions like COUNT, SUM, AVG, which are not accessible with the WHERE clause, thus allowing refined data analysis post-aggregation .

Lists in Python are mutable, allowing for modifications like inserting and deleting elements, which can make them more flexible for use cases requiring frequent changes. Tuples, however, are immutable, meaning once they are created, their contents cannot be altered. This immutability can improve performance, especially in cases where the structure will not change, as tuples can be optimized by the interpreter. Additionally, tuples can be used as keys in dictionaries due to their immutability, unlike lists .

The LIKE operator in SQL is used to search for specified patterns in string columns using wildcards. It enhances pattern matching capabilities by allowing flexible searches, such as partial matches and strings beginning or ending with specific sequences, which is more versatile than exact condition checks. This makes it invaluable in scenarios requiring fuzzy matching or where data might not fully meet strict equality conditions .

Using try and except blocks in Python to handle exceptions allows developers to preemptively manage errors and exceptional cases gracefully, preventing crashes and maintaining program flow even when unforeseen issues arise. This improves software robustness by providing structured error management and enhancing reliability by ensuring that programs can recover or provide meaningful error messages rather than terminating abruptly .

Python lists accommodate dynamic data handling by allowing for mutable operations such as appending, removing, or modifying elements, which is beneficial for programs that require frequent changes to the data structure. The implications of this mutability include potential performance overhead due to dynamic resizing and copying operations, and more complex memory management as lists grow or shrink, affecting speed and memory efficiency compared to immutable structures like tuples .

You might also like