M2) Splitting a tuple

In Listing 1, a program creates a tuple and splits it into two tuples.

Python tuple indices are zero-based. A slice includes its starting index but excludes its stopping index. Therefore, arr1[:b] contains the items before index b, while arr1[b:] starts with the item at index b.

Listing 1: Code that calculates a split boundary, slices the tuple arr1, and prints the two resulting tuples (Question 1).
arr1 = (0, 10, 20, 30, 40, 50)

b = len(arr1) // 2
arr2 = arr1[:b]
arr3 = arr1[b:]

print("1:", arr2, "/ 2:", arr3)

What is printed when the code in Listing 1 is executed?

  1. 1: (True, False, False) / 2: (True, False, False)
  2. 1: (0, 10, 20) / 2: (30, 40, 50)
  3. 1: (0, 10, 20) / 2: (0, 10, 20)
  4. 1: (30, 40, 50) / 2: (0, 10, 20)
  • len(sequence) returns its number of items; len((4, 8, 12)) is 3.
  • For integer operands, // performs floor division: it divides and rounds the result down to an integer. For example, 7 // 2 is 3.
  • print displays its arguments separated by spaces and ends with a new line. For example, print("Value:", 8) displays Value: 8.