知识卡片
函数默认参数需要可执行返回语义
示例question_num默认为None,却直接用questions[question_num]取列表项,默认调用会失败。应明确None表示返回全部还是选择一题,并验证边界;文档说生成列表而实际只取一个,也会误导调用者。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- · 查看原书依据
>>> def generate_question_data(start, stop, step, question_num=None): ... """ Generate list of possible questions with their contexts """ ... seq = seq2str(start, stop, step) ... templates = [ ... f"Let's practice counting {seq2str(start, stop, step)}... " \ ... + f"What is the next number in the sequence after {stop}?", ... f"What number comes {step} after {stop}?\n{seq}", ... f"We're counting by {step}s. " \ ... + f"What
参考来源
- 位置:《Natural Language Processing in Action, Second Edition》第12章《对话引擎与会话设计》(来源项目:a19c7933-4eda-4176-aebd-30fe7e1ad292;源文件:extracted/Natural Language Processing in Action, Second Edition/_epub-src/OEBPS/Text/chapter-12.html)
- 结论依据:摘录中关于函数默认参数需要可执行返回语义的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。
- 原始内容:>>> def generate_question_data(start, stop, step, question_num=None): ... """ Generate list of possible questions with their contexts """ ... seq = seq2str(start, stop, step) ... templates = [ ... f"Let's practice counting {seq2str(start, stop, step)}... " \ ... + f"What is the next number in the sequence after {stop}?", ... f"What number comes {step} after {stop}?\n{seq}", ... f"We're counting by {step}s. " \ ... + f"What