textutils.reverse_text

textutils.reverse_text(text, mode='word')

Reverses the given text either by words or by characters.

Parameters

Name Type Description Default
text str The text to be reversed. required
mode str The mode of reversal. ‘word’ to reverse by words, ‘char’ to reverse by characters. Default is ‘word’. 'word'

Returns

Name Type Description
str The reversed text.

Raises

Name Type Description
ValueError If the mode is not ‘word’ or ‘char’.
TypeError If the input text is not a string.

Examples

>>> reverse_text('Hello World', mode = 'word')
'World Hello'
>>> reverse_text('Hello World', mode = 'char')
'dlroW olleH'