How to reverse a string in Python?

Method 1: Using slicing

>>> s1 = "test"
>>> s2 = s[::-1]
>>> print(s2) 
tset

Method 2: Using for loop (Don't use it)

>>> s1 = "test"
>>> s2 = ""
>>> for char in s1:
...    s2 = char + s2
>>> print(s2)
tset
12/2024