
測試
|
515
範例
16-1
使用
doctest
"""
This module supplies a single function reverse_words that reverses
a string by words.
>>> reverse_words('four score and seven years')
'years seven and score four'
>>> reverse_words('justoneword')
'justoneword'
>>> reverse_words('')
''
You must call reverse_words with one argument, a string:
>>> reverse_words()
Traceback (most recent call last):
...
TypeError: reverse_words() takes exactly 1 argument (0 given)
>>> reverse_words('one', 'another')
Traceback (most recent call last):
...
TypeError: reverse_words( ) takes exactly 1 argument (2 given)
>>> reverse_words(1)
Traceback (most recent call last):
...
AttributeError: 'int' object ...