There are several ways to reverse a string in Python. Here are three common methods:
string = "Hello, World!"
reversed_string = string[::-1]
print(reversed_string)
Output: !dlroW ,olleH
string = "Hello, World!"
reversed_string = ""
for char in string:
reversed_string = char + reversed_string
print(reversed_string)
Output: !dlroW ,olleH
reversed()
function:string = "Hello, World!"
reversed_string = ''.join(reversed(string))
print(reversed_string)
Output: !dlroW ,olleH
All three methods produce the same output, reversing the characters in the original string.