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 programmer has a string s = 'Python programming is fun'. They want to extract the word 'programming'. Which slicing expression achieves this?
A developer needs to check if a string contains only alphanumeric characters. Which string method should be used?
A developer needs to format a floating-point number 123.456789 with exactly 2 decimal places and a width of 10 characters, right-aligned. Which format specifier accomplishes this?
A programmer wants to create a class that cannot be instantiated directly, only through a factory method. Which approach should be used?
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 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 value of matches?
A developer writes a script to read a configuration file that may not exist. The script should handle the error gracefully and continue. Which approach is most Pythonic?
When importing a module, Python searches for it in a specific order. Which of the following lists the correct order of directories searched?
Which THREE of the following are valid ways to import a function named 'calculate' from a module named 'math_ops' located in a subpackage 'operations' of a package 'app'?
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…
A developer uses the .index() method on a string to find the position of a substring. If the substring is not found, what exception is raised?
A programmer wants to restrict a class to only allow specific attribute names and reduce memory usage. Which feature should they use?
Which THREE of the following statements about Python's 'with' statement are true? (Select exactly 3)
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…
Which TWO of the following statements about Python's `sys.path` are true?
What is the result of the expression '12345'[:10]?