04 / 90

Day 04: Values, binding, and observable text

Predict and run Python expressions, distinguish a value from a variable binding, and report observable text/data without confusing a label with the object.

Self-Directed Learning & Python 480 active minutes (8 hours focused study)
01 120 min

Value census and type labels

Independent Mastery Check (no AI assistance).

Prerequisites

Day 03 recovery drill; Python can be launched from the terminal; review the prediction/observation method.

Learning Objective

Use repr(), type(), and bool() to tell apart values that look alike on screen (0, "0", "", None), and explain why the text "0" is not the number 0.

Instructions

Study source: within this activity's existing reading/practice time, use Automate the Boring Stuff with Python, 3rd edition, Chapter 1; Practice Questions; Appendix B answers, then explain one connection to the local task in your own words. Keep the local exercise and acceptance checks; use its original explanation if the external source is unavailable. Required work: Save the following as census.py. Before running it, write a prediction for each output line. Then run python3 census.py, capture the exact output, and compare it with your prediction.

for value in [0, "0", "", None]:
    print(repr(value), type(value).__name__, bool(value))
print("0" == 0, int("0") == 0)

Explain in one or two sentences why "0" (text) and 0 (integer) print differently with repr(), have different types, and have different truth values.

Optional work: only after the required evidence is complete, add one more value of your choice (for example 0.0 or "False") to the list, predict its row, and run again.

Practice & Prediction Log

Predict all five output lines of this program before running it, then record the exact output:

for value in [0, "0", "", None]:
    print(repr(value), type(value).__name__, bool(value))
print("0" == 0, int("0") == 0)

Finally, explain why the text "0" is not numeric zero.

Objective Knowledge Check & Diagnostic Trace

Answer the following questions to verify your understanding. Select your declared assistance condition before submitting.

Declared Assistance Condition

Note: AI-free work is an honest declared condition, not claimed surveillance.

1.

What does print(repr("0"), type("0").__name__, bool("0")) print?

Attempt History & Evidence

    Activity Mastery Criterion

    Your prediction log and observed output contain all five exact lines above, and your explanation names the type difference (str vs int), the truthiness rule (non-empty string is True), and the need for an explicit conversion with int(). The log states the required/optional boundary and that no AI assistance was used.

    Authoritative Source Resources & Provenance

    linking Copyright Al Sweigart; edition-specific reuse terms unverified linking only; no reproduction

    Automate the Boring Stuff with Python, 3rd edition

    Author: Al Sweigart | Original Source Link ↗

    Relevant Section / Range: Chapter 1; Practice Questions; Appendix B answers

    Verified Version & Date: Public edition checked 2026-11-01; moving pages may change

    Selection Rationale:

    Beginner teaching and answer-keyed practice before checking exact semantics in the Python reference; selected chapters only, not the book's entire automation stack.

    Source Prerequisites:

    No prior programming required for Chapter 1; later chapters assume its basic Python concepts.

    Safe Fallback (Offline Resilience):

    Use the original localized explanations, exercises and checks already present in this activity; no external account or purchase is required for that fallback.

    Compared Candidate Sources & Selection Analysis (2)
    The Python Tutorial ↗ compared_alternative [PSF License Version 2]

    Guided Python syntax but assumes programming familiarity; paired with the beginner text rather than used as its replacement.

    MIT OCW 6.0001 ↗ compared_alternative [CC BY-NC-SA 4.0]

    Lectures and problem sets teach a broader CS1 course; the book offers shorter text-first entry and an answer appendix.

    linking PSF License Version 2

    Python Standard Library: Built-in Types

    Author: Python Software Foundation | Original Source Link ↗

    Relevant Section / Range: Sections Truth Value Testing, Comparisons, and Mutable Sequence Types

    Verified Version & Date: Python 3.12 documentation (verified 2026-10-30)

    Selection Rationale:

    Normative reference for truthiness, comparison, binding, and mutation behavior.

    Source Prerequisites:

    Day 03 recovery drill

    Safe Fallback (Offline Resilience):

    Run the included Python examples and consult the installed interpreter help.

    Compared Candidate Sources & Selection Analysis (2)
    Python Data Model reference ↗ compared_alternative [PSF License Version 2]

    Deeper object-semantics reference than the expression-level drills need; stdtypes keeps the operator-level material in scope.

    The Python Tutorial: An Informal Introduction ↗ compared_alternative [PSF License Version 2]

    Narrative introduction to the same operators; the library reference was selected as the normative signature source.

    linking CC BY-NC-SA 3.0 (book) noncommercial share-alike

    Git User Manual: Recording Changes

    Author: Git project | Original Source Link ↗

    Relevant Section / Range: Recording Changes to the Repository

    Verified Version & Date: Verified 2026-10-30

    Selection Rationale:

    Primary reference for inspecting a small diff before a safe commit.

    Source Prerequisites:

    Basic Git awareness

    Safe Fallback (Offline Resilience):

    Use git diff and git status locally; do not commit until the diff is understood.

    Compared Candidate Sources & Selection Analysis (2)
    git-diff command reference ↗ compared_alternative [Git documentation (GPL-2.0)]

    Command-level flag reference; the Pro Git chapter was selected for its guided walkthrough of inspecting changes before committing.

    Atlassian Git tutorials: git diff ↗ compared_alternative [All Rights Reserved]

    Friendly commercial walkthrough; the book chapter provides deeper staging/index semantics for the same inspection habit.

    02 120 min

    Bindings are names, not boxes

    Independent Mastery Check (no AI assistance).

    Prerequisites

    Activity 1 of Day 04 completed; Python can be launched from the terminal.

    Learning Objective

    Trace assignment statements as names bound to objects, and predict that rebinding one name does not change the object another name refers to.

    Instructions

    Required work: Save the following as binding.py. Before running it, write a prediction for each of the three output lines and draw one arrow per assignment from the name to the list object it refers to.

    x = ["draft"]
    y = x
    x = ["replaced"]
    print(y)
    print(x)
    print(x is y)

    Run python3 binding.py, capture the exact output, and explain which binding changed on line 3 and which did not.

    Optional work: only after the required evidence is complete, add print(id(x), id(y)) before and after line 3 and describe what changes.

    Practice & Prediction Log

    Predict the three output lines of this program, run it, and explain which name was rebound:

    x = ["draft"]
    y = x
    x = ["replaced"]
    print(y)
    print(x)
    print(x is y)

    Objective Knowledge Check & Diagnostic Trace

    Answer the following questions to verify your understanding. Select your declared assistance condition before submitting.

    Declared Assistance Condition

    Note: AI-free work is an honest declared condition, not claimed surveillance.

    1.

    After x = ["draft"]; y = x; x = ["replaced"], what does print(y) show?

    Attempt History & Evidence

      Activity Mastery Criterion

      Your prediction log and observed output contain the three exact lines above, your arrow diagram shows y still bound to the original list after line 3, and your explanation says that assignment rebinds a name rather than overwriting the object. The log states the required/optional boundary and that no AI assistance was used.

      Authoritative Source Resources & Provenance

      linking PSF License Version 2

      Python Standard Library: Built-in Types

      Author: Python Software Foundation | Original Source Link ↗

      Relevant Section / Range: Sections Truth Value Testing, Comparisons, and Mutable Sequence Types

      Verified Version & Date: Python 3.12 documentation (verified 2026-10-30)

      Selection Rationale:

      Normative reference for truthiness, comparison, binding, and mutation behavior.

      Source Prerequisites:

      Day 03 recovery drill

      Safe Fallback (Offline Resilience):

      Run the included Python examples and consult the installed interpreter help.

      Compared Candidate Sources & Selection Analysis (2)
      Python Data Model reference ↗ compared_alternative [PSF License Version 2]

      Deeper object-semantics reference than the expression-level drills need; stdtypes keeps the operator-level material in scope.

      The Python Tutorial: An Informal Introduction ↗ compared_alternative [PSF License Version 2]

      Narrative introduction to the same operators; the library reference was selected as the normative signature source.

      linking CC BY-NC-SA 3.0 (book) noncommercial share-alike

      Git User Manual: Recording Changes

      Author: Git project | Original Source Link ↗

      Relevant Section / Range: Recording Changes to the Repository

      Verified Version & Date: Verified 2026-10-30

      Selection Rationale:

      Primary reference for inspecting a small diff before a safe commit.

      Source Prerequisites:

      Basic Git awareness

      Safe Fallback (Offline Resilience):

      Use git diff and git status locally; do not commit until the diff is understood.

      Compared Candidate Sources & Selection Analysis (2)
      git-diff command reference ↗ compared_alternative [Git documentation (GPL-2.0)]

      Command-level flag reference; the Pro Git chapter was selected for its guided walkthrough of inspecting changes before committing.

      Atlassian Git tutorials: git diff ↗ compared_alternative [All Rights Reserved]

      Friendly commercial walkthrough; the book chapter provides deeper staging/index semantics for the same inspection habit.

      03 120 min

      Small diff: make a report safer

      Agent-Assisted Engineering Check: declare the permissions you granted and your review boundary; agent output is not independent mastery evidence.

      Prerequisites

      Activities 1–2 of Day 04 completed; Git installed with user.name and user.email configured; an AI coding agent you may direct.

      Learning Objective

      Direct an agent to make one small, reviewable change that replaces an ambiguous text label with a repr/type report, then verify the diff yourself and commit only that change.

      Instructions

      Required work: Create a practice repository with the original, misleading report:

      git init report-demo && cd report-demo
      printf 'count = "0"\nprint("count=" + count)\n' > report.py
      git add report.py && git commit -m "Add count report"
      python3 report.py

      The program prints count=0, which hides that count is the text "0", not the number 0. The original report.py is:

      count = "0"
      print("count=" + count)

      Ask your agent to change only the print line in report.py so it shows the repr and the type of count. Declare the permission you gave (for example: edit report.py only, no commits). Before running anything, predict what the new output will be. Then review and commit yourself:

      git status --short
      git diff -- report.py
      git diff --check
      python3 report.py
      git add report.py
      git commit -m "Show repr and type in count report"
      git status --short

      If git status lists any file other than report.py (for example ?? notes.txt), it is an unrelated edit: do not stage it; delete or restore it before committing.

      Optional work: only after the required evidence is complete, ask the agent to also print bool(count) and review that second diff the same way.

      Practice & Prediction Log

      Starting from this report.py:

      count = "0"
      print("count=" + count)

      Have an agent change the print line so the output shows count='0' type=str. Record your prediction of the new output, the git status --short and git diff -- report.py output you reviewed, the result of git diff --check, and the commit you made. Reject any unrelated file the agent created.

      Objective Knowledge Check & Diagnostic Trace

      Answer the following questions to verify your understanding. Select your declared assistance condition before submitting.

      Declared Assistance Condition

      Note: AI-free work is an honest declared condition, not claimed surveillance.

      1.

      Before committing the agent's edit, git status --short shows M report.py and ?? notes.txt. You never asked for notes.txt. What is the safe next step?

      Attempt History & Evidence

        Activity Mastery Criterion

        Your log contains your prediction, the reviewed git diff showing only the print line changed, the git diff --check result, the observed output count='0' type=str, a commit that touches only report.py, and a declaration of the permissions you granted the agent. The log states the required/optional boundary and that this work was agent-assisted.

        Authoritative Source Resources & Provenance

        linking PSF License Version 2

        Python Standard Library: Built-in Types

        Author: Python Software Foundation | Original Source Link ↗

        Relevant Section / Range: Sections Truth Value Testing, Comparisons, and Mutable Sequence Types

        Verified Version & Date: Python 3.12 documentation (verified 2026-10-30)

        Selection Rationale:

        Normative reference for truthiness, comparison, binding, and mutation behavior.

        Source Prerequisites:

        Day 03 recovery drill

        Safe Fallback (Offline Resilience):

        Run the included Python examples and consult the installed interpreter help.

        Compared Candidate Sources & Selection Analysis (2)
        Python Data Model reference ↗ compared_alternative [PSF License Version 2]

        Deeper object-semantics reference than the expression-level drills need; stdtypes keeps the operator-level material in scope.

        The Python Tutorial: An Informal Introduction ↗ compared_alternative [PSF License Version 2]

        Narrative introduction to the same operators; the library reference was selected as the normative signature source.

        linking CC BY-NC-SA 3.0 (book) noncommercial share-alike

        Git User Manual: Recording Changes

        Author: Git project | Original Source Link ↗

        Relevant Section / Range: Recording Changes to the Repository

        Verified Version & Date: Verified 2026-10-30

        Selection Rationale:

        Primary reference for inspecting a small diff before a safe commit.

        Source Prerequisites:

        Basic Git awareness

        Safe Fallback (Offline Resilience):

        Use git diff and git status locally; do not commit until the diff is understood.

        Compared Candidate Sources & Selection Analysis (2)
        git-diff command reference ↗ compared_alternative [Git documentation (GPL-2.0)]

        Command-level flag reference; the Pro Git chapter was selected for its guided walkthrough of inspecting changes before committing.

        Atlassian Git tutorials: git diff ↗ compared_alternative [All Rights Reserved]

        Friendly commercial walkthrough; the book chapter provides deeper staging/index semantics for the same inspection habit.

        04 120 min

        Review and independent check

        Independent Mastery Check (no AI assistance).

        Prerequisites

        Activities 1–3 of Day 04 completed.

        Learning Objective

        Without any AI help, predict the output of three short value/binding snippets, check them by running, and explain the root cause of any mismatch.

        Instructions

        Required work: Without AI, write your prediction for every output line of the three snippets below before running any of them. Then run each snippet (for example as a.py, b.py, c.py), capture the exact output, and mark each line as match or mismatch. Explain the root cause of one mismatch; if every prediction matched, explain the snippet you found hardest.

        Snippet A:

        print(repr(None), repr("None"), None == "None")

        Snippet B:

        a = "draft"
        b = a
        a = a + "!"
        print(a, b)

        Snippet C:

        items = ["draft"]
        alias = items
        items = items + ["final"]
        print(alias, items)
        print(alias is items)

        Optional work: only after the required evidence is complete, change one input in one snippet (for example replace "!" with "?" in Snippet B), predict, and run it again.

        Practice & Prediction Log

        Predict, then run, these three snippets and record your predictions next to the exact output:

        Snippet A:

        print(repr(None), repr("None"), None == "None")

        Snippet B:

        a = "draft"
        b = a
        a = a + "!"
        print(a, b)

        Snippet C:

        items = ["draft"]
        alias = items
        items = items + ["final"]
        print(alias, items)
        print(alias is items)

        Explain one mismatch (or your hardest snippet) in terms of value versus binding.

        Objective Knowledge Check & Diagnostic Trace

        Answer the following questions to verify your understanding. Select your declared assistance condition before submitting.

        Declared Assistance Condition

        Note: AI-free work is an honest declared condition, not claimed surveillance.

        1.

        What does n = 5; m = n; n = n + 1; print(m, n) print?

        Attempt History & Evidence

          Activity Mastery Criterion

          Your log shows predictions written before execution, the exact observed output of all three snippets as listed above, and a correct root-cause explanation of one mismatch (or the hardest snippet) in terms of value versus binding. The log states the required/optional boundary and that no AI assistance was used.

          Authoritative Source Resources & Provenance

          linking PSF License Version 2

          Python Standard Library: Built-in Types

          Author: Python Software Foundation | Original Source Link ↗

          Relevant Section / Range: Sections Truth Value Testing, Comparisons, and Mutable Sequence Types

          Verified Version & Date: Python 3.12 documentation (verified 2026-10-30)

          Selection Rationale:

          Normative reference for truthiness, comparison, binding, and mutation behavior.

          Source Prerequisites:

          Day 03 recovery drill

          Safe Fallback (Offline Resilience):

          Run the included Python examples and consult the installed interpreter help.

          Compared Candidate Sources & Selection Analysis (2)
          Python Data Model reference ↗ compared_alternative [PSF License Version 2]

          Deeper object-semantics reference than the expression-level drills need; stdtypes keeps the operator-level material in scope.

          The Python Tutorial: An Informal Introduction ↗ compared_alternative [PSF License Version 2]

          Narrative introduction to the same operators; the library reference was selected as the normative signature source.

          linking CC BY-NC-SA 3.0 (book) noncommercial share-alike

          Git User Manual: Recording Changes

          Author: Git project | Original Source Link ↗

          Relevant Section / Range: Recording Changes to the Repository

          Verified Version & Date: Verified 2026-10-30

          Selection Rationale:

          Primary reference for inspecting a small diff before a safe commit.

          Source Prerequisites:

          Basic Git awareness

          Safe Fallback (Offline Resilience):

          Use git diff and git status locally; do not commit until the diff is understood.

          Compared Candidate Sources & Selection Analysis (2)
          git-diff command reference ↗ compared_alternative [Git documentation (GPL-2.0)]

          Command-level flag reference; the Pro Git chapter was selected for its guided walkthrough of inspecting changes before committing.

          Atlassian Git tutorials: git diff ↗ compared_alternative [All Rights Reserved]

          Friendly commercial walkthrough; the book chapter provides deeper staging/index semantics for the same inspection habit.