Show the Python statement that creates a list called aList and initializes its values to 7, 3, 5, 2, 8, 6.
Show the Python statement that would output the first 2 values of aList. You must use the slice operator (the colon).
Show the Python statement that would output the last 3 values in aList. You must use the slice operator.
Slicing means using : operator to get the required elements.
Code:
# list for given values
list1 = [7, 3, 5, 2, 8, 6]
# Printing first 2 values in list using slicing
print(list1[:2])
# Printing last 3 values in list using slicing
print(list1[:2:-1])
Code screenshot:
Output:
Get Answers For Free
Most questions answered within 1 hours.