Which operator can be used to concatenate two lists in Python?

Study for the PCEP Certified Entry-Level Python Programmer Exam. Access multiple choice questions and detailed explanations to enhance your learning. Prepare effectively for your certification!

The operator used to concatenate two lists in Python is the plus sign (+). When you use this operator between two lists, it combines the elements of both lists into a single list. For example, if you have two lists, list1 = [1, 2, 3] and list2 = [4, 5, 6], using list1 + list2 will produce a new list: [1, 2, 3, 4, 5, 6]. This operation does not modify the original lists; instead, it creates a new list that contains the contents of both.

The other operators listed do not perform concatenation on lists. The minus sign (-) is typically used for arithmetic subtraction and does not apply to lists. The asterisk (*) can be used for repetition of a list (e.g., list1 * 2 would yield [1, 2, 3, 1, 2, 3]), rather than concatenation. The forward slash (/) is used for division and is not applicable to lists either. Thus, the plus sign is indeed the correct and sole operator for concatenating two lists in Python.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy