You must apply PEP 8 and PEP 257 correctly and choose secure logging and secret-handling patterns. The single most important thing is to know the exact PEP recommendations for line length, docstrings, and secret storage, then select the option that follows them.
Start practicing
Best Practices And Coding Conventions — choose a session length
Free · No account required
Domain overview
This domain covers PEP 8 style rules, PEP 257 docstring conventions, and secure coding habits tested on the PCPP1 exam. Questions ask you to choose recommended practices for documentation, logging, secret handling, and line length, so you must recall exact PEP guidance and apply it to refactoring scenarios.
Exam objectives
PEP 257 docstring rules for one-line and multi-line function documentation
PEP 8 maximum line length and naming conventions for modules, classes, and functions
Using the logging module instead of print for configurable diagnostic output
Secure handling of secret keys via environment variables or secret managers
Confusing PEP 8 line length with PEP 257 docstring rules, or picking 79 vs 99 without context.
Assuming print is acceptable for production diagnostics instead of logging with levels and handlers.
Hardcoding secret keys in source or config files instead of using environment variables or vaults.
Click any question to see the full explanation and answer options, or start a focused practice session above.
According to PEP 257, what is the standard format for a single-line docstring?
2When naming a constant in Python, which convention does PEP 8 recommend?
3You are debugging a legacy application and need to ensure that resources like file handles are always closed. Which construct is preferred?
4You are writing a library that expects a custom exception. Which practice aligns best with Python's exception handling hierarchy?
5When implementing secure coding practices in a web-facing Python application, how should you handle raw user input to prevent command injection?
6When documenting a complex function, which approach is most compliant with Google Style Python Docstrings regarding parameter types?
7In a team environment, which PEP 8 guideline should be applied to maintain consistent indentation when mixing spaces and tabs?
8According to PEP 8, what is the maximum recommended length for a line of code?
9When designing a public API, how should you signal that a method is for internal use only?
10You are refactoring code that performs sensitive operations. Which of the following is the most secure practice for handling secret keys?
11A script processes data from untrusted sources. Which technique best mitigates 'pickle' deserialization vulnerabilities?
12What is the primary benefit of using 'logging' over 'print' statements for application diagnostics?
13In the context of writing robust error handling, what is the 'EAFP' principle?
14When writing a library, what is the best practice for documenting the usage of a function?
15Which comment style is preferred for block comments in Python?
16You are implementing a custom context manager using a class. Which methods must be implemented to support the 'with' statement?
17When is it acceptable to ignore PEP 8 guidelines?
18When creating a new project, how should you structure your imports?
19How should one handle the 'KeyboardInterrupt' exception if it must be caught for cleanup purposes?
20What is the recommended way to handle a function that requires a large number of arguments?
21Which TWO of the following are valid conventions for naming in Python according to PEP 8?
22Which THREE practices are recommended when handling external libraries?
23Which TWO of the following are secure coding practices in Python?
24Which TWO practices help maintain clean code when using Python's 'try-except' blocks?
25Which THREE features are associated with robust logging in production applications?
26Which TWO of these are valid PEP 8 recommendations for whitespace?
27Which THREE practices improve documentation maintenance?
28Which TWO of these identify a potential 'code smell' in Python exception handling?
29Which TWO practices ensure secure handling of sensitive environment configurations?
30Which THREE of the following are recommended in PEP 8 for class definitions?
31A code reviewer notices that a Python module defines a class named `dataProcessor` and a function named `processData`. The team follows PEP 8. Which naming convention should be applied to the class name?
32A developer is writing a function that computes the average of a list of numbers. The function should not modify the input list. Which annotation best communicates this intent and aligns with PEP 484 best practices?
33A developer is writing a Python function that accepts a mutable default argument, such as `def add_item(item, items=[])`. A code reviewer flags this as a potential bug. Which statement best explains the issue and the recommended fix according to best practices?
34A developer is adding a new public function `calculate_discount` to an existing Python module. The module currently uses four spaces per indentation level, and the function spans several nested `if` blocks. Which PEP 8 indentation practice should the developer follow?
35You are designing a Python class that manages a database connection. The class has a method `_execute_query` that should only be used internally. According to Python best practices and PEP 8, how should you indicate that this method is for internal use only?
36A team is reviewing code and notices that a function uses a mutable default argument: def append_to(element, target=[]):. Which change best adheres to Python best practices and avoids unexpected behavior?
37A team is reviewing a module where a helper function `_normalize_path` is prefixed with a single underscore. A new developer asks which statement best describes the intent of that naming choice according to common Python conventions.
38A developer is documenting a function `fetch_records` that accepts a database connection, a table name, and an optional limit. The team follows Google Style Python Docstrings. Which approach correctly documents the parameters and their types?
39A developer is writing a Python script and wants to ensure that the code adheres to PEP 8's recommendations for blank lines. According to PEP 8, how many blank lines should surround a top-level function definition?
40A Python developer is writing a function that reads a configuration file and returns a dictionary. They want to follow PEP 8 and best practices for function design and documentation. Which two of the following should they do? (Choose two.)
41A developer is writing a Python module and wants to follow best practices for documenting functions. Which TWO of the following are recommended by PEP 257 for docstrings? (Choose two.)
42A developer is writing a Python script that contains a class named `DataProcessor`. According to PEP 8, which naming convention should be used for the class's methods and attributes?
43A developer is writing a Python module and wants to follow PEP 8's recommendations for imports. The module currently has the following imports: `import os`, `import sys`, `import requests`, `from collections import defaultdict`. According to PEP 8, how should these imports be grouped and ordered?
44A Python developer is reviewing code and notices that a function has a default argument value set to an empty list: `def append_to(element, target=[]):`. According to best practices, what is the recommended way to handle mutable default arguments?
45You are preparing a Python module for PyPI. Your project layout is: project_root/ ├── setup.py ├── src/ │ └── mypackage/ │ ├── __init__.py │ └── core.py └── tests/ └── test_core.py You want to write a test that imports mypackage.core and verifies the function add(a, b). Which import statement should you use at the top of tests/test_core.py to follow best practices for a src-layout project after installing the package in editable mode?
46A developer is reviewing a pull request where a function uses a global variable to track a counter. The reviewer suggests refactoring to avoid global state. Which refactoring best follows best practices for maintainability and testability?
47A developer is writing a module-level variable that holds the maximum number of retries for a network client and will never change during runtime. Which naming convention does PEP 8 recommend for this constant?
48A developer is writing a Python script that processes sensitive data. They want to ensure that any errors are logged without exposing the sensitive data itself. Which logging practice should they follow to avoid leaking sensitive information in logs?
49You are developing a Python application that uses a third-party library. You need to ensure that your code handles exceptions raised by that library in a way that is both robust and follows best practices. The library raises a custom exception named LibraryError, which is a subclass of Exception. Your function calls a method that may raise LibraryError. Which of the following is the best approach to handle this exception?
50You are writing a Python module that includes a function to compute the factorial of a number. You want to document the function using a docstring that is compatible with the Google Python Style Guide. Which of the following docstrings correctly follows the Google style for documenting parameters and return values, including types?
51A development team is refactoring a legacy Python module. They want to enforce a consistent import ordering convention across the codebase. According to PEP 8, which grouping and ordering of imports is considered best practice?
52A developer is writing a Python function that accepts a callback. They want to ensure the function's docstring follows PEP 257 conventions for multi-line docstrings. Which of the following is the correct format for a multi-line docstring?
53A developer is writing a Python script and wants to ensure that lines do not exceed the recommended maximum length according to PEP 8. What is the maximum line length that PEP 8 recommends for code?
You must apply PEP 8 and PEP 257 correctly and choose secure logging and secret-handling patterns. The single most important thing is to know the exact PEP recommendations for line length, docstrings, and secret storage, then select the option that follows them.
The Courseiva PCPP1 question bank contains 53 questions in the Best Practices And Coding Conventions domain. Click any question to see the full explanation and answer breakdown.
Start with a 10-question focused session to identify your baseline accuracy in this domain. Read every explanation — even for questions you answer correctly — to understand the reasoning. Once you score consistently above 80%, move to a 20–30 question session to confirm depth before moving to the next domain.
Yes — the session launcher on this page draws questions exclusively from the Best Practices And Coding Conventions domain. Choose 10, 20, 30, or 50 questions for a focused session, or click individual questions to review them one by one.
Save your results, see per-domain analytics, and get readiness scores — free, for every certification.
Sign Up FreeFree forever · Every certification included