注册 登录
编程论坛 Python论坛

typeError: can't concatenation 'str' and 'int' objects

tony_wang 发布于 2011-08-25 13:27, 495 次点击
a = 12
print 'a = '+int(a)
typeError: can't concatenation 'str' and 'int' objects

我是开始接触python的新手,
请有经验的前辈解释一下为什么不能用int(a),而必须用str(a)?
2 回复
#2
外部三电铃2011-08-25 22:19
'a='是字符串型,所以跟它相连(相加)的也必须是字符串型,就是str(a)

而int(a)是整数型,当然会错误了
#3
tony_wang2011-09-07 17:11
多谢!
1