Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

Python Interview Question

The document contains a series of informative and scenario-based questions regarding Python, covering topics such as data types, memory management, decorators, and performance optimization. It also includes several coding exercises to implement functions like calculating factorials, checking for palindromes, and merging lists. Additionally, there are questions with explanations about list references and function behavior in Python.

Uploaded by

vkscribdind
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Python Interview Question

The document contains a series of informative and scenario-based questions regarding Python, covering topics such as data types, memory management, decorators, and performance optimization. It also includes several coding exercises to implement functions like calculating factorials, checking for palindromes, and merging lists. Additionally, there are questions with explanations about list references and function behavior in Python.

Uploaded by

vkscribdind
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Informative Questions

1. What are the key features of Python that make it suitable for
data engineering?
2. Explain the difference between mutable and immutable data
types in Python.
3. What is the Global Interpreter Lock (GIL), and how does it affect
multi-threading in Python?
4. Describe how memory management works in Python.
5. What are decorators in Python, and how can they be used to
enhance functions?
Scenario-Based Questions
1. You have a large dataset that needs to be processed efficiently.
How would you optimize your Python code for performance?
2. Imagine you need to read a CSV file with millions of rows. What
strategies would you use to handle this efficiently in Python?
3. You encounter a memory leak in your Python application. How
would you diagnose and fix it?
4. How would you handle exceptions in a data pipeline to ensure
data integrity?
5. If you had to design a REST API using Flask, what considerations
would you take into account for performance and scalability?
1. Write a function to calculate the factorial of a number using recursion.
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
2. Implement a function that checks if a string is a palindrome.
def is_palindrome(s):
return s == s[::-1]
3. Write a program to merge two sorted lists into one sorted list.
def merge_sorted_lists(list1, list2):
return sorted(list1 + list2)
4. Create a function that returns the Fibonacci series up to n numbers.
def fibonacci(n):
fib_series = [0, 1]
while len(fib_series) < n:
fib_series.append(fib_series[-1] + fib_series[-2])
return fib_series[:n]
5. Write a function that removes duplicates from a list while maintaining the
order of elements.
def remove_duplicates(lst):
seen = set()
return [x for x in lst if not (x in seen or seen.add(x))]
1. Question: What will be the output of the following code?
x = [1, 2, 3]
y=x
y.append(4)
print(x)
Answer: The output will be [1, 2, 3, 4]. This is because y is a reference to the
same list object as x. Modifying y also modifies x.
2. Question: What does the following code print?
def func(a, b=[]):
b.append(a)
return b

print(func(1))
print(func(2))
print(func(3, []))
Answer: The output will be:
text
[1]
[1, 2]
[3]
The second call modifies the default list b, while the third call provides a new
list.
3. Question: What will be the output of this code snippet?
a = [1, 2, 3]
b=a
a[0] = 0
print(b)
Answer: The output will be [0, 2, 3]. Similar to the first question, b references
the same list as a, so changes to a affect b.
4. Question: Consider the following code. What will it output?
def foo(x):
return x * 2

print(foo(3) + foo(5))
Answer: The output will be 16. This is
because foo(3) returns 6 and foo(5) returns 10, and their sum is 16.
5. Question: What does this code print?
x = [1, 2, 3]
y=x
y = y + [4]
print(x)
Answer: The output will be [1, 2, 3]. In this case, y is reassigned to a new list
that concatenates [4], which does not affect the original list referenced by x.

You might also like