Free CompTIA PenTest+ PT0-002 Practice Question

While reviewing a penetration testing script written in Python, you identify a function designed to process a list of hostnames and their associated services. The goal is to add a tuple containing a new hostname and service to the existing list, while ensuring that this addition is the last element and maintains the list's structure. Which of the following methods should you choose to accomplish this while adhering to best practices and considering performance?

  • Using the append() method for the host and service tuple

  • Using the += operator to concatenate a new list with the host and service tuple

  • Utilizing the insert() method, providing the index as the current list length for the host and service tuple

  • Expanding the list with extend() method using the host and service tuple

This question's topic:
CompTIA PenTest+ PT0-002 / 
Tools and Code Analysis
Your Score:

Check or uncheck an objective to set which questions you will receive.