Code is executable intent—notes to your future self that a machine actually runs. Python is the friendliest on-ramp to AI and data; you don’t need to be “a math person,” just patient.
Learning Objectives
By the end of this module, you will be able to:
- Run Python in Colab or locally and read basic errors calmly.
- Use variables, strings, numbers, lists, dicts,
if/for, and functions. - Debug off-by-one and type mistakes with traceback habits.
- Ship a small personal script as portfolio evidence.
1. Why Python?
Readable syntax, huge community, same language as many AI tutorials.
Fun Fact: Python is named after Monty Python, not snakes.
2. Setup
Colab: colab.research.google.com → new notebook → Shift+Enter to run a cell.
Local (optional): python -m venv .venv, activate, pip install jupyter, run notebook.
Try This! In one sentence, what would you like to automate this semester?
3. Variables, Types, Lists, Dicts (Explain Like You’re Texting)
- Strings hold text; ints whole numbers; floats decimals; bools True/False.
- Lists are ordered—indexes start at 0 (classic “computers count from zero” moment).
- Dicts map labels to values—great for one “student card” with keys like
"gpa"and"clubs".
Common errors: SyntaxError (quotes/parens), NameError (typo), IndentationError (spacing in loops/functions).
Concept: Read the last line of the red error first—it usually names the problem.
4. Decisions and Loops
if / elif / else choose paths. for repeats over a list or range. while repeats while a condition holds—easy to make infinite loops on purpose or by accident.
Try This! With a friend, trade three-line broken snippets—first fix wins a snack.
5. Functions
A function names a job once: inputs (parameters) → output (return). Docstrings (triple-quoted comments) remind future-you what you promised.
Why it matters: Same spirit as later “tool use” in AI—small, testable pieces.
6. Strings and Tiny Data Stories
strip(), lower(), split(), f-strings like f"Hi {name}" clean messy text. Real projects spend tons of time on boring text cleanup—get cozy early.
7. Debugging Mindset
Errors are messages, not grades. Uncomment one broken line at a time; read the bottom of the traceback aloud; fix; rerun.
Hello, World
Key Example: Your first run + comment style. Everything else in this module extends these two ideas: print output and # comments.
[object Object],
,[object Object],(,[object Object],)
,[object Object],(,[object Object],)Stretch (no new code block): Change the strings to introduce you; add a variable name and an f-string greeting; deliberately break a quote and fix it.
Practice Challenges
input() age + name; list min/max/avg; tiny quiz with dicts in a list; password length checker; three-friend favorite-subject dict.
Your Challenge
Personal utility (50+ lines with comments): study timer, streak counter, club RSVP logger, or deadline list—two functions, one loop, one if branch, one edge case handled.
Discuss: Can a classmate guess what your script does from the first comment block only? If not, clarify the README-style top lines.
Key Takeaways
- Python is readable and everywhere in AI tutorials.
- Indices and types cause most early bugs—slow down.
- Functions organize chaos.
- Errors are normal—even for pros.
Key Takeaway
- Treat Python as clear instructions, not magic—computers do exactly what you wrote.
- Zero-based indexing and types (
"3"vs3) are where beginners trip—check them first. - Functions + loops are the skeleton of almost every automation you’ll build later.
- Read tracebacks from the bottom up; fix one error at a time.
- Ship one small working program—proof beats intentions.
Going Further
Next: Module 05 (data + plots). Later: Module 08 to save .py / .ipynb as receipts.
You made a machine follow your instructions. That’s not small.