Video by freeCodeCamp.org · taught by David J. Malan · streamed from YouTube. All rights remain with the creator.
Lesson 7: Python
About this lesson
This lecture introduces Python and shows how much shorter and simpler programs become in a higher-level language. It begins by translating the C programs of earlier weeks into Python, starting with printing a greeting, and draws attention to what disappears: semicolons, curly braces, type declarations and the main function that C requires. You see how indentation defines blocks, how variables are created without declaring types, and how format strings make printing values easy. The lecture covers conditions, Boolean operators and the different loops, and explains that Python programs are usually run by an interpreter instead of being compiled first, which makes them quicker to write but generally slower to run. It then shows features that C lacks or makes hard: integers that never overflow, strings that can be compared and changed with simple methods, and built-in structures including lists that grow automatically, tuples, dictionaries and sets. Throughout, earlier problems are revisited and the speller exercise of the previous weeks is reimplemented in far fewer lines, with a discussion of the trade-off between programmer time and running time. The lecture also covers defining functions, the convention of a main function in Python, handling errors with exceptions when user input cannot be converted, reading command-line arguments, working with files, and using libraries that others have written. Afterwards, read Chapter 7 of the course book, which compares the syntax of the two languages side by side.