我有两个问题和答案,它们都是列表,每个都包含3个字符串。我必须通过功能render_responses()
我尝试了下面显示的代码,但所有尝试似乎都失败了
QUESTIONS = [
'Please explain your Python, Django and Django Rest Framework experience.',
'What is your favorite feature of Python 3 and when did you use it?',
'What is the most annoying aspect of Django or DRF?'
]
# TODO: Add your answers
ANSWERS = ["I took 2 classes through university both which were taught in python.", "me", "bee"]
def render_responses(questions, answers):
# TODO: Render your responses out to the console
questions = QUESTIONS
answers = ANSWERS
if questions == []:
return("There are no questions")
elif answers == []:
return("There are no answers")
else:
return(questions[0], answers[0], questions[1], answers[1], questions[2], answers[2])
代码可以编译,但仅在我放置print(render_responses)时返回<函数render_responses于0x7fa2b1942b70>
答案 0 :(得分:1)
重要的是要注意,在python中,几乎所有东西都是对象。包括功能。 render_responses
是一个函数对象,您可以在此行上打印它:
print(render_responses)
如果您想调用该函数,请在其后加上括号并为其提供必要的参数:
print(render_responses(questions, answers))
答案 1 :(得分:0)
您不是在调用函数,只是在打印名称和有关该函数的一些元数据。
使用
print(render_responses())