Before class · do this at home
Watch, read, then come
CS50x 2026 · Week 6: Python by David J. Malan. Watch the lecture on YouTube (you are also enrolled on edX), read the notes, skim the slides. Our lecture builds on it instead of repeating it.
- Watch the lecture and, for each program, write the C version in your head first. The point of the week is the comparison.
- Run
python3in your codespace terminal and typeprint("hello, world"). That is the whole setup.
Learning objectives
By the end of this week you can:
- 1 Translate C programs with variables, conditions, loops and functions into Python.
- 2 Use Python's built-in types: int, float, str, bool, list, dict, tuple, and explain dynamic typing.
- 3 Handle input and exceptions with try/except and write input-validation loops.
- 4 Import and use modules (random, csv, sys) and install packages with pip.
- 5 Explain what an interpreter is, and why Python is slower than C but faster to write.
- 6 Recognize when C is the right tool and when Python is.
★ the wow moment
CS50's speller: 200 lines of C become 20 lines of Python, and the Python version is still a hash table.
Python's set is a hash table written in C. Everything you built by hand in week 7 is one line: words = set(open('dictionary').read().split()). You did not waste week 7: you now know what that line costs and why it is fast. That is the difference between using a tool and understanding it, and it is the difference employers pay for.
Topics
- Hello, again:
print("hello, world"); running withpython3; no compile step; the interpreter. - Types without declarations:
int,float,str,bool;input()returns a string;int(input());try/except ValueError. - Conditions and loops: indentation instead of braces;
if/elif/else;while;for i in range(n);for c in s. - Lists and dicts:
scores = [72, 73, 33],sum(scores) / len(scores);people = {"Carter": "+1-617"}; the hash table from week 7, built in. - Functions and modules:
def, default arguments,import random,from cs50 import get_int,sys.argv,sys.exit. - Files:
open,csv.reader,csv.DictWriter. - C versus Python: overflow gone, floats still imprecise, speed 10–100× slower, and why that is usually fine.
Full notes are published before the lecture. The lab, Lab 7: C to Python, rewrites three earlier labs in Python and times the difference.
In industry
-
Python is the language of AI and data
PyTorch, TensorFlow, pandas, scikit-learn: every machine-learning system is driven from Python, while the heavy lifting runs in C and CUDA underneath.
-
Glue and automation
Most companies run thousands of Python scripts that move data, call APIs, generate reports and test systems. Knowing Python means never doing a repetitive task by hand again.
-
Interpreters and the speed trade-off
Instagram, YouTube and Dropbox run on Python, and each has rewritten hot paths in C or Rust. Knowing both is the actual industry skill.
-
pip and the supply chain
A one-line install pulls code written by strangers. The 2024 xz backdoor showed why professionals pin versions and read what they install.
Lab 7: C to Python
Rewrite three earlier labs in Python, use lists and dictionaries instead of arrays and hash tables, and time C against Python on the same task. Python · due Fri, Nov 20 · 23:59 · 10 points · opens in week 9 Open lab instructions →Go deeper
- CS50x 2026 · Week 6 notes
- The Python Tutorial (official) · Chapters 3–5 cover this week.
- CS50's Introduction to Programming with Python · A whole free course if you want more.
Tags:Pythoninterpreterdynamic typinglistdictexceptionsmodulespip