textutils.reverse_text
textutils.reverse_text(text, mode='word')
Reverses the given text either by words or by characters.
Parameters
| 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' |
Raises
|
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'