def myFunc(King):
print("The characters name is " + King.name + " and age is " + King.age)
如何将int链接到字符串?
答案 0 :(得分:4)
这恰好表示错误消息所说的内容:display
是一个字符串。您不能在其中添加整数("The characters name is " + King.name + " and age is "
。
幸运的是,您可以使用多种解决方法:
King.age
print("The characters name is", King.name, "and age is", King.age)
(需要Python> = 3.6 print(f"The characters name is {King.name} and age is {King.age}")
print("The characters name is {King.name} and age is {King.age}".format(King=King))
...
答案 1 :(得分:0)
def myFunc(King):
print("The characters name is " + str(King.name) + " and age is " + str(King.age))