我正在學習python,並且在這裏遇到了一些新問題。任何人都可以解釋這個Python代碼內部發生了什麼。字符串串聯失敗
>>> s="sam"
>>> s +="dam"
>>> s
'samdam'
>>> d +=s
>>> d
'msamdam'
>>> f = f+s
Traceback (most recent call last):
File "<pyshell#129>", line 1, in <module>
f = f+s
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>> f +=s
Traceback (most recent call last):
File "<pyshell#130>", line 1, in <module>
f +=s
TypeError: unsupported operand type(s) for +=: 'int' and 'str'
代碼中的f是什麼? – HH1
你能更新你的代碼以包含d和f的instanciations嗎? – Fabien