TypeError: can only concatenate str (not “int”) to str
与 java 不同,python 的拼接字符串应写为:
msg = '我有%d'%(self.num) + '个苹果'
不能写为:
msg = '我有' + (self.num) + '个苹果'
本文揭示了Python中字符串拼接的常见误区,重点在于理解为何'+'操作不能直接连接整数与字符串,并提供正确的拼接方式。
TypeError: can only concatenate str (not “int”) to str
与 java 不同,python 的拼接字符串应写为:
msg = '我有%d'%(self.num) + '个苹果'
不能写为:
msg = '我有' + (self.num) + '个苹果'

被折叠的 条评论
为什么被折叠?