Truthiness table for real inputs
Independent Mastery Check (no AI assistance).
Prerequisites
Day 05 comparison check completed; you can run a Python file with python3 and read its output.
Learning Objective
Predict and verify bool() for empty, zero, and whitespace inputs, and explain why an `if value:` branch can mislabel real data.
Instructions
Required work: Before running anything, write down your prediction of bool(value) and of the branch presence(value) ("present" when the value is truthy, otherwise "missing") for each of [], [0], "", " ", 0, and "0". Then run the program, copy the exact output, and mark every row where your prediction differed.
Review: For each mismatch, write one sentence that states the rule: empty containers and numeric zero are falsy; every non-empty string, including " " and "0", is truthy.
Optional work: Only after the required evidence is complete, add None and [[]] to the list, predict them first, then run.
Practice & Prediction Log
Create truthiness.py that defines presence(value) (return "present" when value is truthy, otherwise "missing") and prints repr(value), bool(value), and presence(value) on one line for each of [], [0], "", " ", 0, "0", in that order.
A string is falsy only when its length is 0, so " " (one space) and "0" are truthy. A list is falsy only when it is empty, so [0] is truthy even though its single element is falsy.
Reference solution (truthiness.py):
def presence(value):
if value:
return "present"
return "missing"
for value in [[], [0], "", " ", 0, "0"]:
print(repr(value), bool(value), presence(value))
Exact output (Python 3.13 and 3.14):
[] False missing
[0] True present
'' False missing
' ' True present
0 False missing
'0' True present
Explanation: [], "", and 0 are falsy, so the branch reports them as "missing". [0], " ", and "0" are truthy, so the branch reports them as "present". Two rows mislead: whitespace-only text is reported as present although it carries no data, and the number 0 is reported as missing although it is a real value. When the meaning matters, test explicitly (for example text.strip() == "" or value is None) instead of relying on truthiness.
Objective Knowledge Check & Diagnostic Trace
Answer the following questions to verify your understanding. Select your declared assistance condition before submitting.
In the truthiness table, which input is truthy, so presence(value) reports it as "present", even though it holds no visible data?
bool(" ") is True because the string has length 1. "" and [] are empty, so they are falsy and reported as "missing".
The truthiness of a string depends only on its length, not on what its characters look like.
Attempt History & Evidence
Without AI assistance, your prediction for all six inputs is written before execution, your captured output matches the reference exactly, and you correctly explain both misleading rows (`" "` reported present, `0` reported missing). Required and optional work are kept separate, and your evidence states the independent assistance condition.
Authoritative Source Resources & Provenance
Python Standard Library: Built-in Types
Relevant Section / Range: Sections Truth Value Testing, Comparisons, and Mutable Sequence Types
Verified Version & Date: Python 3.12 documentation (verified 2026-10-30)
Normative reference for truthiness, comparison, binding, and mutation behavior.
Day 03 recovery drill
Run the included Python examples and consult the installed interpreter help.
Compared Candidate Sources & Selection Analysis (2)
Deeper object-semantics reference than the expression-level drills need; stdtypes keeps the operator-level material in scope.
Narrative introduction to the same operators; the library reference was selected as the normative signature source.
Git User Manual: Recording Changes
Relevant Section / Range: Recording Changes to the Repository
Verified Version & Date: Verified 2026-10-30
Primary reference for inspecting a small diff before a safe commit.
Basic Git awareness
Use git diff and git status locally; do not commit until the diff is understood.
Compared Candidate Sources & Selection Analysis (2)
Command-level flag reference; the Pro Git chapter was selected for its guided walkthrough of inspecting changes before committing.
Friendly commercial walkthrough; the book chapter provides deeper staging/index semantics for the same inspection habit.