pls give Output of this.. pls
Answers
Given code:
Output:
Explanation:
A tuple 'tpl' has been assigned the values (10, 20, 14, 20, 22, 24, 30, 32, 34). The command after it is trying to obtain an extract of the tuple, or rather, slicing the tuple. Slicing in Python is the process of obtaining a sub-part of an already existing part. Slicing here has been done with the help of index values. Index values start from 0 [positive indexing] as we move from left to right, and start with -1 [negative indexing] as we move from right to left. The syntax of a slice command is as follows:
- start - represents the position from where the slicing needs to start.
- stop - represents the position at which the slicing needs to stop.
- step - represents the number of values it needs to skip as it slices.
If no values have been mentioned, by default, the range will start from 0, and end at the last value, skipping no values.
As per the question, the range we were given was [::3]. This indicates that the start value, as mentioned earlier, if there is no value mentioned, by default, is 0. And the stop value is the position of the last element in the list. We're however given a step value, 3. This means that it takes every 3rd value from the tuple, thereby giving us the output, (10, 20, 30).