Sample questions
Certified Associate Python Programmer PCAP practice questions
A developer is implementing a custom exception for invalid data. Which class should the custom exception inherit from?
A team is developing a large Python application with multiple modules. They encounter an ImportError when module A tries to import from module B, and module B tries to import from…
A developer needs to check if a string contains only alphanumeric characters. Which string method should be used?
Which THREE statements about inheritance in Python are correct?
A programmer wants to create a class that cannot be instantiated directly, only through a factory method. Which approach should be used?
An application uses a heavy-weight class DatabaseConnection that establishes a network connection upon instantiation. The class is used in multiple places, and the developer wants…
A developer implements a custom exception class `DataError` that inherits from `Exception`. Which method override is essential to ensure the exception message is properly displayed…
A developer creates a Python class with a method that is intended to be overridden in subclasses. Which approach best ensures that the method is not accidentally called on the base…
A team is using a shared Python environment where multiple projects have conflicting dependencies. Which approach is the best practice to isolate project dependencies?
A developer creates a package 'mypackage' with the following structure: mypackage/ __init__.py module1.py module2.py The __init__.py contains: from mypackage.module1 impor…
What is the output of the following code? try: exec('1/0') except: print('error') else: print('no error') finally: print('done')
Consider the code fragment: f = open('data.txt', 'r') data = f.read() process_data(data) f.close() What is the primary risk if an exception occurs during process_d…
Which THREE of the following statements about Python's module search path are true?
You are designing a class that should behave like a sequence and support slicing. Which special methods must be implemented?
Which of the following statements about the __init__.py file in a package is true?
A developer is working on a class hierarchy for geometric shapes. They have a base class Shape with an abstract method area(). They also have a mixin class Drawable that provides a…
You are working on a legacy system that processes financial transactions. The system uses a class hierarchy: Transaction (base), Deposit, Withdrawal, Transfer. Each subclass overri…
Which of the following correctly uses an abstract base class to enforce that all subclasses implement a 'make_sound' method? (Assume ABC imported)
A developer needs to combine a list of 10,000 strings into a single string. Which approach is most efficient in terms of memory and performance?
A team is developing a large application and wants to organize code into packages. Which of the following is a best practice for package design?
Which of the following is a correct use of the @property decorator to create a getter and setter for an attribute named 'score' that ensures score stays between 0 and 100?
A developer notices that a custom package 'mypackage' is not being found when importing, even though it is installed in the site-packages directory. The developer suspects a confli…
Which of the following is the BEST practice for building a large string by concatenating many smaller strings in Python?
A developer has two separate directories on sys.path: /home/user/libs and /opt/libs. Both directories contain a subdirectory 'mypackage' without an __init__.py file. The developer…