Home »
Python »
Python Tuples MCQs
In python tuples, what is the syntax of the slicing operator?
22. In python tuples, what is the syntax of the slicing operator?
- Tuple[start:end]
- Tuple[start: end:steps]
- Only A
- Only B
- Both A and B
Answer: E) Both A and B
Explanation:
Both Tuple[start:end] and Tuple[start:end:steps] are the correct syntaxes of the slicing operator in python tuples.
Consider the following example:
tpl = (10, 20, 30, 40, 50)
print(tpl) # Prints (10, 20, 30, 40, 50)
print(tpl[0:5]) # Prints (10, 20, 30, 40, 50)
print(tpl[0:5:2]) # Prints (10, 30, 50)