I recently had a Python interview with EPAM and wanted to share the questions in case it helps anyone:
- What are decorators? How do multiple decorators work?
def decorator1(func):
def wrapper(*args, **kwargs):
print("Decorator 1: Before function call")
result = func(*args, **kwargs)
print("Decorator 1: After function call")
return result
return wrapper
def decorator2(func):
def wrapper(*args, **kwargs):
print("Decorator 2: Before function call")
result = func(*args, **kwargs)
print("Decorator 2: After function call")
return result
return wrapper
@decorator1
@decorator2
def my_function():
print("Inside my_function")
my_function()- What is exception handling? Why do we order multiple exceptions in the except block?
try:
# Code that might raise exceptions
value = int("abc") # This will raise a ValueError
result = 10 / 0 # This will raise a ZeroDivisionError
except ValueError as e:
print(f"Invalid input: {e}")
# Specific handling for ValueError
except ZeroDivisionError as e:
print(f"Cannot divide by zero: {e}")
# Specific handling for ZeroDivisionError
except Exception as e:
print(f"An unexpected error occurred: {e}")
# Catch-all for any other exceptions (use with caution)- What would happen if you raise exception from error?
def demo_no_catch():
try:
raise Exception('general exceptions not caught by specific handling')
except ValueError as e:
raise Exception from e- What is multiple inheritence? How would it work if two classes are inherited by a class both of which have the same named method. What would be the output?
class ParentA:
def common_method(self):
print("Method from ParentA")
class ParentB:
def common_method(self):
print("Method from ParentB")
class Child(ParentA, ParentB):
pass
child_obj = Child()
child_obj.common_method()- What is context management in Python? How does it work for a Flask app?
- How does dependency injection work in flask app with sqlalchemy?
- Difference between a monolith and a microservice. When do we use one over the other?
- How do we deploy microservices?
- How do microservices communicate with each other?
- When do we use events?
#EPAM #Python
Comments (2)


