AI Skill Report Card
Applying Boolean Operations
Quick Start13 / 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 x→Trueifxis false, elseFalse. Always boolean.x and y→ evaluatesx; ifxis false, returnsx(unevaluatedy); else returnsy.x or y→ evaluatesx; ifxis true, returnsx(unevaluatedy); else returnsy.- Both
and/orshort-circuit: the second operand is only evaluated if needed. nothas lower priority than non-Boolean operators, sonot a == bisnot (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).
Workflow12 / 15
- Identify whether you need a strict boolean (
True/False) or an operand value.- Strict boolean → wrap with
bool(...)or usenot not x, or prefer explicit comparisons. - Operand value (e.g., default fallback) → use
or/anddirectly.
- Strict boolean → wrap with
- Order operands so the cheap/safe check comes first — it determines whether the expensive/unsafe one runs.
- Use
andas a guard:obj and obj.method()avoids calling onNone/falsy objects. - Use
orfor defaults:value = user_input or fallback— but beware falsy-but-valid values (0,"",[]). - Chain carefully:
a and b or cis not a ternary; ifbis falsy,cwins even whenais true. Useb if a else cinstead.
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.
Examples15 / 20
Example 1 — safe attribute access: Input:
Pythonconfig = None timeout = config and config.get("timeout")
Output: timeout = None (short-circuits before calling .get)
Example 2 — default value pitfall: Input:
Pythoncount = 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:
Pythonresult = 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:
Pythonx = 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'.
Best Practices
- Prefer
if/elseor conditional expressions (a if cond else b) overand/orchains when you need real ternary behavior. - Use
and/orfor 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, andFalseare all falsy. - Combine with
is Nonechecks when falsy-but-valid values (0,"") must be distinguished from "missing."
Common Pitfalls
- Assuming
and/orreturnTrue/False— they return one of the operands. - Using
a and b or cas a ternary — fails silently whenbis falsy. - Forgetting
not's low precedence, leading to unintended groupings likenot a == b. - Relying on
orfor defaults when0,"", 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).