reverse string
时间: 2023-10-02 18:11:38 浏览: 139
To reverse a string, you can iterate through the characters of the string from the last to the first and append them to a new string. Here's an example in Python:
```python
def reverse_string(input_string):
reversed_string = ""
for char in input_string[::-1]:
reversed_string += char
return reversed_string
input_string = "Hello, World!"
reversed_string = reverse_string(input_string)
print(reversed_string)
```
Output: `!dlroW ,olleH`
阅读全文