โ† All PCEP Flashcard Decks

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
  1. What is the difference between a module and a script in Python?

    Answer: A module is imported for reuse; a script is executed directly

    Modules are designed for importing while scripts are designed for direct execution, though the same file can serve both purposes.

  2. How does Python determine the search path for modules?

    Answer: Through sys.path which includes current directory, PYTHONPATH, and installation directories

    Python searches multiple locations in order as defined in sys.path.

  3. What is the purpose of __name__ == "__main__" in Python?

    Answer: To run code only when the file is executed directly, not when imported

    This guard ensures code runs only during direct execution, not when the file is imported as a module.

  4. What are built-in exceptions in Python?

    Answer: Pre-defined exception classes like ValueError, TypeError, IndexError

    Python provides a hierarchy of built-in exception classes for common error types.

  5. How do you create a custom exception in Python?

    Answer: Define a class that inherits from Exception

    Custom exceptions are created by defining a class that inherits from the Exception class or its subclasses.

  6. What is the purpose of the else clause in try-except?

    Answer: Runs only if no exception was raised in the try block

    The else clause executes when the try block completes without raising any exceptions.