2(ix)
What will be the output of the following Python code?
s = "Python" print(s[: :-1])
Show SolutionHide Solution↓
nohtyP
The string "Python" is stored in the variable s. The slice s[::-1] uses a step of -1, which reverses the string by reading all its characters from the last to the first.
Hence, the output is nohtyP.