In python tuples, what is the syntax of the slicing operator?

22. In python tuples, what is the syntax of the slicing operator?

  1. Tuple[start:end]
  2. Tuple[start: end:steps]
  3. Only A
  4. Only B
  5. 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)

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.