Error Handling and Modules Flashcards
6 cards from real PCEP practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 6 Error Handling and Modules flashcards as text
What is the purpose of a try-except block in Python?
Answer: To handle exceptions and prevent program crashes
Try-except blocks catch and handle exceptions that would otherwise terminate the program.
What does the finally clause do in Python exception handling?
Answer: Executes code regardless of whether an exception occurred
The finally block always executes, making it ideal for cleanup operations.
How do you import a specific function from a module in Python?
Answer: from module import function
The from...import syntax allows importing specific names from a module.
What is a Python package?
Answer: A directory containing modules and an __init__.py file
Packages organize related modules in a directory structure with an __init__.py file.
What exception is raised when dividing by zero in Python?
Answer: ZeroDivisionError
Python raises ZeroDivisionError specifically for division by zero operations.
What is the purpose of the raise statement in Python?
Answer: To manually trigger an exception
The raise statement allows you to deliberately throw an exception in your code.