【发布时间】:2017-11-24 03:07:12
【问题描述】:
我正在学习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 是什么?
-
您能否更新您的代码以包含 d 和 f 的实例?
标签: python string concatenation