Python String Reversal

Document 对象参考手册Python3 Examples

Given a string, then reverse it and output it in reverse order.

Example 1: Using string slicing

str='Example' print(str[::-1])

Executing the above code produces the following output:

boonuR

Example 2: Using reversed()

str='Example' print(''.join(reversed(str)))

Executing the above code produces the following output:

boonuR

Document 对象参考手册Python3 Examples

Other Extensions