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.
arr1, and prints the two resulting tuples (Question 1).
What is printed when the code in Listing 1 is executed?
1: (True, False, False) / 2: (True, False, False)1: (0, 10, 20) / 2: (30, 40, 50)1: (0, 10, 20) / 2: (0, 10, 20)1: (30, 40, 50) / 2: (0, 10, 20)
TipHint
len(sequence)returns its number of items;len((4, 8, 12))is3.- For integer operands,
//performs floor division: it divides and rounds the result down to an integer. For example,7 // 2is3. printdisplays its arguments separated by spaces and ends with a new line. For example,print("Value:", 8)displaysValue: 8.