Automation, Orchestration, and Scripting

A script defines services = ['sshd', 'nginx', 'cron']. Which of the following expressions evaluate to a value of the Boolean data type? (Choose three.)

Choose 3 answers

Show the answer

Correct answersA. len(services) > 2C. 'nginx' in servicesD. services[0] == 'sshd'

AWhy this is right: A comparison such as 3 > 2 evaluates to True, a Boolean.

BWhy not this: len() returns the integer 3; it is truthy in a condition but its type is int.

CWhy this is right: The in operator tests membership and returns True or False.

DWhy this is right: The == comparison returns a Boolean, here True.

EWhy not this: index() returns the integer position of the item, here 2.

FWhy not this: Slicing a list returns a new list, here the last two items.

Membership tests and comparison operators return True or False, which are Boolean values. len(services) is tempting because it appears in a condition, but it returns the integer 3, and only the comparison against 2 yields a Boolean. services.index('cron') returns the integer 2, and services[1:] returns a new list.