AI Skill Report Card

Applying Boolean Operations

B-62·Aug 12, 2026·Source: Web
13 / 15
Python
# and/or return operands, not True/False x = None y = x or "default" # "default" z = x and x.upper() # None (short-circuits, avoids AttributeError) # not always returns True/False flag = not [] # True

Key facts (Python and, or, not):

  • not xTrue if x is false, else False. Always boolean.
  • x and y → evaluates x; if x is false, returns x (unevaluated y); else returns y.
  • x or y → evaluates x; if x is true, returns x (unevaluated y); else returns y.
  • Both and/or short-circuit: the second operand is only evaluated if needed.
  • not has lower priority than non-Boolean operators, so not a == b is not (a == b).
Recommendation
This is fairly basic Python semantics that Claude already knows well; consider whether this warrants a full skill vs. a brief note, or scope it to a more specialized/advanced angle (e.g., codebase-specific linting rules or performance implications).
12 / 15
  1. Identify whether you need a strict boolean (True/False) or an operand value.
    • Strict boolean → wrap with bool(...) or use not not x, or prefer explicit comparisons.
    • Operand value (e.g., default fallback) → use or/and directly.
  2. Order operands so the cheap/safe check comes first — it determines whether the expensive/unsafe one runs.
  3. Use and as a guard: obj and obj.method() avoids calling on None/falsy objects.
  4. Use or for defaults: value = user_input or fallback — but beware falsy-but-valid values (0, "", []).
  5. Chain carefully: a and b or c is not a ternary; if b is falsy, c wins even when a is true. Use b if a else c instead.
Recommendation
Add a real-world scenario example (e.g., reviewing a PR with buggy 'a and b or c' logic) rather than only isolated snippets, to show the skill applied in context.
15 / 20

Example 1 — safe attribute access: Input:

Python
config = None timeout = config and config.get("timeout")

Output: timeout = None (short-circuits before calling .get)

Example 2 — default value pitfall: Input:

Python
count = 0 display = count or "N/A"

Output: display = "N/A"0 is falsy, so this may be a bug if 0 is a valid count. Fix: display = count if count is not None else "N/A".

Example 3 — fake ternary trap: Input:

Python
result = True and 0 or "fallback"

Output: "fallback" — even though the condition (True) suggests 0 should win, 0 is falsy so or moves to the next operand. Use 0 if True else "fallback" to get 0.

Example 4 — not precedence: Input:

Python
x = 5 print(not x == 5)

Output: False, because it parses as not (x == 5).

Recommendation
Workflow section is more a checklist of rules than a process; tighten it into concrete decision steps or a flowchart for 'when to use and/or vs if/else'.
  • Prefer if/else or conditional expressions (a if cond else b) over and/or chains when you need real ternary behavior.
  • Use and/or for their natural short-circuit purpose: guards and defaults, not general branching.
  • When you need a real boolean (e.g., for JSON serialization or strict typing), coerce explicitly with bool(...).
  • Remember truthiness: 0, 0.0, "", [], {}, set(), None, and False are all falsy.
  • Combine with is None checks when falsy-but-valid values (0, "") must be distinguished from "missing."
  • Assuming and/or return True/False — they return one of the operands.
  • Using a and b or c as a ternary — fails silently when b is falsy.
  • Forgetting not's low precedence, leading to unintended groupings like not a == b.
  • Relying on or for defaults when 0, "", or [] are legitimate values.
  • Evaluating expensive/side-effecting code in the second operand without realizing short-circuiting may skip it entirely (or unexpectedly not skip it).
0
Grade B-AI Skill Framework
Scorecard
Criteria Breakdown
Quick Start
13/15
Workflow
12/15
Examples
15/20
Completeness
13/20
Format
14/15
Conciseness
13/15