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?

Answer: A. print(TXT[::-1])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…

  1. A.

    print(TXT[::-1])

  2. B.

    print(TXT[-1])

  3. C.

    print(TXT[1-1])

  4. D.

    print(TXT[0:-1])

Attempted by 333 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.

Explore the full course: Bpsc

Loading lesson…