
Already know some of this? A 2-minute test skips the lessons you know.
Take the placement testA free 92-lesson course built from CS50's 15h 54m of YouTube playlist. 10 days at 90 minutes a day, with study notes and a quiz in every lesson. A 2-minute placement test skips what you already know.
Taught by CS50 on YouTube. Videos play in YouTube's own player, so the creator keeps every view.
Understand the course structure, topics covered (functions, conditionals, loops, exceptions, libraries, testing, file I/O, regex, OOP), prerequisites, and learning approach.
Learner will be able to create and run a basic Python program using VS Code and the command line interface.
Learner will be able to use built-in functions with arguments, recognize side effects, and interpret syntax errors to debug code.
Learner will be able to capture function return values using variables and the assignment operator to reuse data in a program.
Learner will be able to document code with comments and design programs using pseudocode to outline logic before implementation.
Learner will be able to pass multiple arguments to the print function and concatenate strings using the + operator.
Learner will be able to control output formatting by using the sep and end named parameters of the print function.
Learner will be able to chain string methods like strip, title, and capitalize to sanitize and format user input.
Learner will be able to convert string input to integers using the int() function to enable mathematical operations.
Learner will be able to use float for decimal values and explain the precision limitations of floating-point representation.
Learner will be able to format numbers with commas and specific decimal places using f-string format specifiers and the round function.
Learner will be able to perform division, round results to a specified precision, and compare rounding approaches.
Learner will be able to create reusable functions using def, parameters, and indentation to encapsulate logic.
Learner will be able to use the return keyword to send values back from a function for use in the calling code.
Learner will understand what conditionals are and identify the six comparison operators used to form boolean expressions in Python.
Learner will be able to simplify a series of range checks by relying on the if-elif order to imply upper bounds.
Learner will be able to write a function that returns a boolean expression directly instead of using an if-else block.
Learner will be able to simplify functions by returning the boolean expression itself, making code more concise and readable.
Learner will be able to replace a long if-elif-else chain with a match statement using case clauses for exact value matching.
Implement while loops using a counter variable to repeat actions, learning to avoid infinite loops by updating the counter correctly.
Use for loops to iterate over explicitly defined lists of values, introducing the list data type and square bracket syntax.
Leverage string multiplication for concise repetition and control print formatting using the 'end' parameter to remove unwanted newlines.
Simplify list iteration by looping directly over list elements (e.g., student names) instead of using numeric indices.
Create and access dictionaries to associate keys with values (e.g., students with houses), using curly brace syntax and string-based indexing.
Model complex entities by constructing a list of dictionaries, each containing multiple key-value pairs like name, house, and patronus.
Loop through a list of dictionaries to access and print specific values (e.g., student name and house) using nested key lookups.
Implement nested loops to print 2D grids (like Mario bricks), then refactor using string multiplication and function decomposition for cleaner abstraction.
Catch a ValueError when converting user input to an integer using try and except blocks to provide a user-friendly error message.
Resolve a NameError caused by variable scope issues in try-except blocks by moving successful code into an else clause.
Implement a robust input loop using while True, try-except, and break to repeatedly reprompt the user until valid integer input is received.
Use the pass keyword in an except block to silently ignore invalid input and reprompt the user without printing an error message.
Refactor the input validation logic into a reusable get_int function that accepts a custom prompt argument, demonstrating function arguments and defensive programming.
Learn to import the random module, use random.choice(), and distinguish between 'import module' and 'from module import function' syntax.
Use random.randint() for random integers in a range and random.shuffle() to randomize a list in place.
Access command-line arguments via sys.argv to make programs accept input at launch instead of prompting interactively.
Detect and handle IndexError when accessing sys.argv, and validate argument counts with conditionals for user-friendly errors.
Install external packages from PyPI using pip, and understand the difference between standard-library and third-party modules.
Use the requests package to query a REST API, parse JSON responses with the json module, and extract nested data like track names.
Write your own .py module, import its functions with 'from ... import', and guard execution with 'if __name__ == __main__' to prevent side effects on import.
Create a separate test file that imports functions and uses if-statements to check return values against expected results.
Wrap assertions in try-except blocks to catch AssertionError and print user-friendly failure messages.
Install and run pytest to automatically discover and execute test functions, eliminating the need for manual test runners and try-except boilerplate.
Split a large test function into multiple focused functions (e.g., positive, negative, zero) so pytest runs all tests independently and reports each result.
Refactor functions that print (side effects) to return values instead, making them pure and easily testable with assertions.
Understand the need for persistent storage beyond in-memory lists and learn to collect multiple user inputs into a list.
Learn to open a file in write mode using open(), write a string to it with write(), and close it to save data persistently.
Read a file in read mode, iterate over its lines, and use rstrip() to remove trailing newlines before printing.
Load all lines into a list, sort them alphabetically or in reverse using sorted() with the reverse parameter, then print the sorted results.
Encounter the limitation of naive comma splitting when data fields contain commas, motivating the use of Python's csv module for robust parsing.
Use csv.reader to automatically handle commas, quotes, and newlines, iterating over parsed rows as lists of fields.
Sort a list of dictionaries by a specific key using the key parameter in sorted(), and simplify with anonymous lambda functions.
Read multiple image files from command-line arguments using Pillow, combine them into an animated GIF, and save with duration and loop settings.
Learn to validate email addresses using basic string methods like 'in', 'split', and 'endswith', and recognize the limitations of this approach.
Escape regex metacharacters with backslash and use raw strings (r'...') to prevent Python from interpreting backslashes.
Use re.sub to find and replace pattern matches, enabling data cleaning like reformatting 'Last, First' to 'First Last'.
Create and use tuples to return multiple values from a function, and understand immutability as a tool for defensive programming.
Use dictionaries to store key-value pairs with meaningful keys, improving code readability over positional tuple indexing.
Define a class using the `class` keyword, instantiate objects via the constructor, and store instance attributes using dot notation.
Define custom instance methods (like `charm`) that operate on `self` to give objects behavior beyond data storage.
Raise `ValueError` exceptions inside `__init__` to enforce data integrity (e.g., non-empty name, valid house) at object creation time.
Use `@property` and `@attribute.setter` decorators to validate and control attribute access, preventing invalid modifications after initialization.
Recognize that Python's built-in types are classes with methods (e.g., `str.lower`, `list.append`), revealing OOP has been used all along.
Define `@classmethod` and class variables (e.g., `houses` in `Hat`) to share data and functionality across all instances without instantiation.
Create a parent `Wizard` class and use inheritance (`class Student(Wizard)`) with `super().__init__()` to eliminate redundant initialization code.
Implement `__add__` to define custom behavior for the `+` operator, enabling intuitive combination of custom objects like `Vault` instances.
Learn to use Python's set data type to automatically eliminate duplicate values from a collection.
Understand variable scope, the difference between local and global variables, and how to modify globals inside functions using the global keyword.
Refactor global variable usage into a class with instance variables and properties for better encapsulation.
Add type hints to functions and variables, then use mypy to catch type-related bugs before runtime.
Write standardized docstrings using triple quotes and reStructuredText conventions to document functions for tools and collaborators.
Use the argparse library to robustly parse command-line flags and arguments instead of manually handling sys.argv.
Use * and ** to unpack lists, tuples, and dictionaries into positional and keyword arguments when calling functions.
Define functions that accept a variable number of positional and keyword arguments using *args and **kwargs.
Transform sequences using map or the more Pythonic list comprehension syntax for concise, readable code.
Filter sequences using the filter function with a predicate, optionally replacing named functions with anonymous lambdas.
Build dictionaries in a single expression using dictionary comprehension syntax with curly braces.
Create memory-efficient generators using yield to produce values lazily instead of building large lists in memory.