If marks = (20,30,18,15,33) is a tuple in python, then what will be the new value of marks variable after executing the statement marks = marks[::-1]?
a. (33,15,18,30,20)
b. (19,29,17,14,32)
c. (33,18,20)
d. error as tuple is immutable
Answers
The answer is (a) (33, 15, 18, 30, 20).
We're given a tuple with the values 20, 30, 18, 15 and 33.
A tuple is a series of elements separated by commas and enclosed in simple brackets.
The next statement is:
This is similar to indexing/slicing. The syntax for a slice command is as follows:
- start - represents the index it needs to start from
- stop - represents the index it needs to stop at
- step - represents how many values it needs to skip while traversing/slicing
If nothing has been mentioned in the command, the default values are considered to be taken from the first element to the last element, with a step value of 1.
In the statement, we have the slice command as [::-1].
This means that it will consider all the elements in the object, or the tuple in this case, and store it backwards since the step value is a negative number.
If a negative number is given as a step value, the object is stored/printed in reverse order.
Hence, the tuple after being stored into marks would be:
(33, 15, 18, 30, 20)
To know more about slicing/indexing, refer to the link below:
brainly.in/question/16088533