Correct option is D
The print statement
print(L[-1], L[1:]) will display the content of the list in the following way: 60, 10, 20, 30, 40, 50. Here's why:
·
L[-1] accesses the last element of the list, which is 60.
·
L[1:] accesses all elements starting from the second element, i.e., 10, 20, 30, 40, 50.
· When combined in the print statement, it will display 60, 10, 20, 30, 40, 50.
Important Key Points:
1.
Negative Indexing:
L[-1] accesses the last element of the list, which is 60.
2.
List Slicing:
L[1:] is a slice that gets all elements from index 1 to the end of the list, which is [10, 20, 30, 40, 50].
3.
Print Format: The
, in the print statement ensures that the elements are printed with a space in between.
Knowledge Booster:
·
Option (a):
L[-1] + L[1:] would result in a
TypeError because you cannot concatenate an integer (L[-1], which is 60) with a list (L[1:]). This would lead to a mismatch in types.
·
Option (b):
L[-1] + L[1:len(L)-1] would also attempt to concatenate an integer with a list, which would cause an error. It also does not produce the correct desired output format.
·
Option (c):
L[len(L)-1] + L[1:len(L)] would lead to a
TypeError due to concatenating an integer with a list, similar to option (a). Also, this slicing wouldn't correctly rearrange the elements in the desired order.