Python method to reverse output string
Method 1: Use list reversed function
class Solution(object): def reverse_string(self, s): if len(s) > 1: reversed_s = ''.join(reversed(s)) return reversed_s return s
Method 2: Use sharding (commonly used)
def string_reverse(str): return str[::-1]
The above is the detailed content of Reverse output of a string using Python. For more information, please follow other related articles on the PHP Chinese website!