word="testing"
tup_1=tuple(word)
word2=str(tup_1)
assert "('t','e','s','t','i','n','g')" == word2
它看起来只是正确的,但是给出了断言错误。
为什么会出现错误?谁能解释?
答案 0 :(得分:2)
由于字符串不相等,因此产生错误。之间有空格:
>>> assert "('t','e','s','t','i','n','g')" == word2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AssertionError
>>> assert "('t', 'e', 's', 't', 'i', 'n', 'g')" == word2
>>>