类型错误:只能将 str (不是 "Element" ) 连接到 str



我在打印东西时遇到了问题

错误:

TypeError: can only concatenate str (not "Element") to str

代码:

print(('Currently the weather in '+ query + 'is' + weath + 'with the temperature at ' + temp + 'degrees celsius'))

对于实例的自定义字符串表示

class A:
def __init__(self, value):
self.value = value
def __str__(self):
return self.value

print('string ' + str(A('concatenation')))
#string concatenation

不含__str__

class B:
def __init__(self, value):
self.value = value
print('string ' + str(B('concatenation')))
#string <__main__.B object at 0x7f91f5dd5040>

最新更新