为什么return语句输出错误的字符串/ int格式?

时间:2014-12-11 23:42:24

标签: python-2.7 return

为什么这个程序的return语句用括号和引号输出答案?

示例输出:('The age of the oldest child is', 6)

虽然当我使用print语句而不是return时,格式化是否正确?

带有print语句的示例输出:The age of the oldest child is 6

def ageOfOldest():

    age_youngest = input("Enter the age of the youngest child: ")
    age_middle = input("Enter the age of the middle child: ")

    age_of_oldest = (age_middle - age_youngest) + age_middle
    return "The age of the oldest child is ", age_of_oldest


print ageOfOldest()

1 个答案:

答案 0 :(得分:0)

因为你正在返回一个元组。请尝试返回字符串。

return "The age of the oldest child is {}".format(age_of_oldest)