我正在学习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