从元组转换为字符串时删除空格时出错

时间:2018-06-28 03:20:42

标签: python tuples

word="testing"
tup_1=tuple(word)
word2=str(tup_1)
assert "('t','e','s','t','i','n','g')" == word2

它看起来只是正确的,但是给出了断言错误。

Error

为什么会出现错误?谁能解释?

1 个答案:

答案 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
>>>