Automation, Orchestration, and Scripting

During code review of a log-processing script, a reviewer asks the author to rewrite a check to test whether the list named hosts is empty. Which statement follows the PEP 8 recommendation for this check?

Show the answer

Correct answerB. if not hosts:

PEP 8 recommends relying on the fact that empty sequences are false, so if not hosts is preferred. Checking len(hosts) == 0 works but is explicitly discouraged. Comparing to False is also wrong because an empty list is falsy but not equal to False.