知识卡片

问题卡 · 6258.d

输入互斥不等于输入有效

理解等级:中级

异或判断只保证两个参数中恰有一个不是None,不能证明它是非空、类型正确或内容有效。随后items = screen_names or user_ids按真值取值:传空screen_names且user_ids为None仍通过断言,却把items设为None并在len处失败。输入存在性、空集合语义和合法值校验需要分开。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • · 查看原书依据

      (screen_names != None) != (user_ids != None), \ "Must have screen_names or user_ids, but not both" items_to_info = {} items = screen_names or user_ids while len(items) >0: # Proces

    参考来源

    - 位置:《社交网站的数据挖掘与分析(原书第2版)》第9章《9.17.3 讨论》(spine143;extracted/OReilly精品图书系列共21册(《Javascript权威指南》、《机器学习:实用案例解析》、《编写可读代码的艺术》、《算法精解》等)/_epub-src/text/part0132.html;u205-ch09-024)。 - 结论依据:原文在“(screen_names != None) != (user_ids != None)”附近的定义、例子或代码支撑本卡核心说明:异或判断只保证两个参数中恰有一个不是None,不能证明它是非空、类型正确或内容有效。边界按已读前提解释;示例未执行。 - 原始内容:(screen_names != None) != (user_ids != None), \ "Must have screen_names or user_ids, but not both" items_to_info = {} items = screen_names or user_ids while len(items) >0: # Proces