Skip to content
Book a Call → mycocoon.life
← Back to Blog Students 10 min read

CS50 Week 6 Explained: Python After C

After five weeks of C, Week 6 feels like taking off heavy boots. Python does in a few lines what took you pages. The lecture opens by rewriting the Week 5 spell checker in about twenty lines. But the ideas haven't changed: you're doing the same things with far less ceremony, and now you know what's happening underneath.

🎓
An unofficial study guide. CS50 is Harvard University's Introduction to Computer Science, taught by David J. Malan. The lectures, notes and problem sets linked here belong to Harvard and are shared under CC BY-NC-SA 4.0. This guide is Cocoon's own writing and is not affiliated with or endorsed by Harvard. Take the course itself, free, at cs50.harvard.edu/x. Part of our CS50 study series. Keep track of your progress with our free CS50 Study Tracker.
CS50 Week 6 Explained: Python After C, pixel-art illustration
CS50 Week 6 Explained: Python After C
Thumbnail of CS50x 2026, Lecture 6: Python
Watch the lecture

CS50x 2026, Lecture 6: Python

2 h 30 min · Harvard University · CS50 on YouTube

Jump to the key moments

  1. 0:43Python
  2. 6:13Speller in Python
  3. 16:51Functions
  4. 38:16Data types
  5. 1:02:55Object-oriented programming
  6. 1:32:58Exceptions
  7. 1:50:20Lists
  8. 1:54:08Dictionaries
  9. 2:08:35sys
  10. 2:14:02csv
  11. 2:22:04pip

What changes from C

The types you'll use constantly

str (text), int, float, bool (True or False), list (a growable array), tuple (a fixed group of values), dict (keys mapped to values, which is a hash table built into the language) and set (unique values). Most Python programs are built from lists and dicts.

Objects and methods

In Python, values come with their own functions, called methods. Instead of passing a string to toupper, you write name.upper(). The lecture introduces this briefly as object-oriented programming, and you'll lean on it constantly: .lower(), .strip(), .split(), .append().

Exceptions

When something goes wrong, such as converting "cat" into an int, Python raises an exception instead of returning a special value. You catch it with try and except ValueError and ask again. It's cleaner than C's "check every return value", but only if you catch the specific exception you expect.

Libraries: sys, csv, and pip

sys.argv gives you command-line arguments (as argc and argv did in C), and sys.exit(1) sets the exit status. The csv module reads spreadsheet-style files, and csv.DictReader gives you each row as a dictionary keyed by the column headings. pip installs other people's libraries. The ecosystem of those libraries is a big part of why Python is so widely used, AI included.

Problem Set 6: what it asks

Most of this set is "Sentimental": re-solving earlier problems in Python so you can see the two languages side by side.

Where people get stuck

Check yourself

What does Python use instead of curly braces to group code?

Indentation. The lines indented under an if, for or def are its body.

Can a Python int overflow the way a C int does?

No. Python integers grow as big as they need to. Floats still have limited precision, though.

Which built-in type is Python's version of the hash table you built in Speller?

The dictionary (dict). Sets are hash-based too.

How do you ask again when a user types letters where you wanted a number?

Loop, and inside the loop try converting with int(). Catch ValueError and ask again. Break out of the loop once the conversion succeeds.

Python is the language of AI. See the full journey from Python to building with AI in Cocoon's programmes.

See Cocoon programmes →