我是这个地区的新手,帮我找出错误
name = input( "Enter your name:" )
age = 12
print( "Hi, " + name + " " + age + " years old!" )
$ python test.py
Enter your name:evgen
Traceback (most recent call last):
File "test.py", line 5, in <module>
print( "Hi, " + name + " " + age + " years old!" )
TypeError: can only concatenate str (not "int") to str
在连接之前,需要将int转换为str:
还可以看看python的字符串格式化:https://docs.python.org/3.4/library/string.html#format-examples
您正在将字符串与整数
age
连接起来。简单地将age
转换为str
,如下所示:相关问题 更多 >
编程相关推荐