Which of the following slicing examples will display content of string TXT in…
2026
Which of the following slicing examples will display content of string TXT in reversed order in Python?
- A.
print(TXT[::-1])
- B.
print(TXT[-1])
- C.
print(TXT[1-1])
- D.
print(TXT[0:-1])
Attempted by 146 students.
Show answer & explanation
Correct answer: A
In Python, string slicing uses the syntax [start:end:step]. To reverse a string, you can use the slice notation [::-1], which starts at the end of the string and steps backwards by 1 to the beginning. This effectively reverses the order of characters in the string.