
This course includes our updated coding exercises so you can practice your skills as you learn.
See a demo
Welcome to Learn to Code with Python! In this introductory lesson, we'll explore the history and purpose of the Python programming language, and take care of some basic housekeeping for the course.
Get to know a little about your instructor.
Discusses the differences between the complete and incomplete course files.
Download a PDF containing all the code written in the Learn to Code with Python course.
Provides helpful notes for following along with installation videos.
The Terminal is an application for issuing text commands to the operating system. Long before graphical interfaces, programmers used the Terminal to interact with their computers. Today, the Terminal still offers many advantages -- it's much faster and offers more options for customizing commands. In this lesson, we introduce 3 of the most popular commands needed to interact with the Terminal.
The pwd (print working directory) command to output the current directory
The ls (list) command to output all files and folders in the current directory
The cd (change directory) command to navigate up and down across directories.
In this lesson,, we head to the official Python website to download the latest version of Python, 3.8. We run through the installation process and then verify proper installation by issuing a few Terminal commands.
Download and install the VSCode code editor on a macOS computer.
In this lesson, we introduce the Command Prompt, an application for issuing text commands to the operating system. We walk through common commands for navigating across the filesystem, displaying files and folders, and creating / deleting directories. You'll use the Command Prompt occasionally throughout the course to run Python files.
In this lesson, we download and install the latest version of Python for our Windows computers. We walk through the steps of the installer and verify that the setup was successful.
Microsoft's Visual Studio Code will serve as our text editor throughout the course (although you are welcome to use any editor of your choice). In this lesson, we download and install VSCode for our Windows machine.
In this lesson, we take a quick tour of the VSCode interface including the project explorer, the search tab, and the extensions tab. We also include some popular shortcuts for navigating around the editor and working with text.
Python offers its own command line application called the interactive prompt. This is a quick and dirty playground where we can experiment with Python. No code is saved to a file for later use. In this lesson, we discuss the process for launching and terminating the prompt, and run a few sample commands.
In this optional lesson, I'll share a few tips and tricks that I wish someone had told me when I was learning to code. Programming is an arduous task and it's important to approach it with patience -- you're not going to learn to code over a day, a week, or a month. It requires a consistent effort over several hundreds of hours of practice.
This article wraps up Section 1 and offers a preview of the features in the course.
Everything in Python is an object. An object is a data structure, a way of storing digital information. The first object we'll dive into is a string, a collection of zero or more characters in order. In this lesson, we use string literal syntax to declare several strings and begin a discussion on the concept of immutability.
A function is a sequence of one or more steps. It's an procedure, a routine, a set of instructions for Python to follow to accomplish a task. There are functions built into the core language and functions that the developers can define. Functions can accept inputs called arguments and produce outputs called return values. In this presentation, we explore the idea of functions with the analogy of a cooking recipe.
The declaration of a value (like a string) does not output it to be seen. The print function is a built-in tool which prints its argument(s) to the screen. In this lesson, we invoke the print function with a variety of inputs including strings, numbers and mathematical expressions. We also introduce concatenation, the process of combining two strings together.
The print function accepts any number of sequential arguments. It will print them all out, separating each with a default delimiter of a single space. In this lesson, we continue practicing invoking the function and observing the results.
A parameter is the name of an expected input to a function. The argument represents the actual value passed to the parameter when the function is invoked. In this lesson, we use keyword argument syntax to pass the print function the sep and end parameters. These customize the characters placed between subsequent printed objects as well as the string placed at the end of all output.
A comment is a line of text that is ignored by Python interpreter. Developers can use comments to leave documentation, explain the reasoning for a technical decision, or even temporarily disable one or more lines of code. In this lesson, we use the hashtag symbol (#) to turn lines into comments.
Learn more about the in-browser coding exercises scattered throughout the course.
See how to solve the problems in the previous coding challenge.
An expression is a Python statement that is evaluated. Expressions require the use of operators. An operator is a special symbol that carries out some kind of operation, such as a plus sign for addition. The values to the left and right of an operator are called operands. In this lesson, we introduce operators for addition, subtraction, concatenation, multiplication, and exponentiation.
Python 3 offers two options for division: floating point division with / and floor division with //. In this lesson, we discuss the differences between the two approaches. We also introduce the modulo operator (%) for returning the remainder of a division operator.
A Boolean is a special data type that can only be one of two values: True or False. The majority of the time, the Boolean is a data type that you’ll arrive at from some evaluation. In this lesson, we introduce the equality operator (==) and the inequality operator (!=) for comparing the equality / inequality of two different objects.
The equality and inequality operators are not the only ways to arrive at Boolean values. Python also includes various mathematical operators for testing relationships like less than, greater than, less than or equal to, and greater than or equal to. In this lesson, we introduce the characters for these operations.
The type function returns the class that an object is constructed from. A class is a blueprint or template or a schematic for creating objects. An instance is an object from a class. In this lesson, we invoke the type function with a variety of objects including integers, floating points, strings, Booleans and more.
In a complex program, data may not always arrive in the type that we need to store it as. Python is bundled with several helper functions to convert one object to another. In this lesson, we introduce int for converting an object to an integer, float for converting an object to a float, and str for converting an object to a string. We also discuss situations where Python performs automatic type conversion for us.
A variable is a name assigned to an object. It's a label or placeholder or an identifier for an object. A good real-life analogy is the address of a house. In this lesson, we declare and assign variables to a variety of different data types. We conclude with a discussion on Python's dynamic type system and how it compares to the statically typed systems in languages like Java and C++.
Python has a collection of reserved keywords. These are words (such as len and print) that are defined and used within the language itself. As developers, we cannot use these words for our variable names. This article features a complete list of the keywords as well as additional tips related to the naming of variables.
See how to solve the problems in the previous coding challenge.
Python allows us to assign multiple variables to the same value or the same object. There is also a shorthand syntax available to assign multiple values to multiple variables on the same line. In this lesson, both options are discussed.
The augmented assignment operator acts as a shortcut for overwriting a variable value based on its current or existing value. In this lesson, we discuss the original syntactical option for overwriting a value and why the augmented assignment operator proves more beneficial.
Python's built-in input function collects user input from the Terminal as a string. In this lesson, we practice prompting the user for input, then collecting it in a variable, and displaying it back. We conclude by developing a program that adds two numbers from the user together.
Errors are a regular part of programming and they come in many different forms -- syntactical, logical, even language-specific. When an error occurs in Python, the interpreter produces a traceback, a record and summary of the exception. In this lesson, we introduce 4 error varieties -- NameError, ValueError, TypeError, and SyntaxError -- and debug their issues from the traceback message.
A function is a collection of one or more Python statements that accomplishes a goal or task. In this lesson, we define a simple function that outputs three lines of text to the screen. We also discuss how functions allow for code organization, structure, and reuse.
A parameter is the name of an expected input to a function. The argument is the actual value provided for the input when the function is invoked. In this lesson, we expand on the foundation from the previous lesson to define a function with a single parameter. We discuss what happens when the function is invoked with an insufficient number of arguments.
Arguments can be passed to a function in two ways: sequentially without parameter names or with keyword arguments. In this lesson, we define a base add function and practice invoking it in a variety of formats. We conclude by showing how a single invocation can include both positional and keyword arguments.
An output from a function is called a return value. Functions return an output with the return keyword. In this lesson, we modify our add function to return its calculation instead of just printing it.
See how to solve the problems in the previous coding challenge.
Default arguments are fallback arguments that are passed to a function if the invocation does not include an explicit value for that parameter. In this lesson, we continue expanding our add function to be able to provide default arguments.
See how to solve the problems in the previous coding challenge.
In this lesson, we introduce None, a special object used to represent nothingness or nullness or the absence of a value. If an explicit value is not returned from a function, Python will implicitly return None. In this lesson, we declare a function without an implicit return to observe the effect in action.
An annotation is an additional piece of information about something, much like a footnote in a book. Function annotations allow us to add metadata or additional information about the expected type of each function argument as well as its return value. In this lesson, we discuss the special colon and arrow syntax to declare types.
Welcome to the Strings: The Basics section of the course. In this one, we’ll be exploring the string data type in depth. This lesson begins with a discussion of the len function to obtain the number of characters in a string, followed by a review of concatenation and the concept of immutability.
See how to solve the problems in the previous coding challenge.
Each character in a string is assigned a numeric position that represents its place in line. That position is called the index, sometimes also called the offset. The index position starts counting at 0. In this lesson, we practice extracting various characters from a string by using square brackets to index into a given index position.
The square brackets used to extract a character from a string also accepts a negative integer. The value represents the element to pull out relative to the end of the string. For example, -1 means the last character and -2 means the second-to-last character. In this lesson, we practice the syntax with a sample programming string.
See how to solve the problems in the previous coding challenge.
Multiple characters can be extracted from a string using slicing syntax, which combines square brackets with one or more numbers. The number to the left of the colon indicates the starting index and is inclusive. The number to the right of the colon represents the ending index and is exclusive. There are also shortcuts available to pull from the beginning of a string or to the end of a string.
In this lesson, we continue practicing with string slicing syntax. We also introduce an optional third number to the square brackets, which represents the stride or step interval. This is the amount of index positions that will be jumped over between every character extraction.
See how to solve the problems in the previous coding challenge.
An escape character is a symbol that the Python interpreter treats differently from regular text. In this lesson, we introduce the \n character for line breaks, \t character for tabs, as well as special characters for escaping single quotes, double quotes, and backslashes.
In this lesson, we introduce the in and not in operators for checking for the presence of a substring in another string (a concept known as inclusion). Both of the operators return a Boolean value -- either True or False. The operators are inverses of each other. If in returns True, the not in operator will return False, and vice versa.
In this section, we'll explore a variety of methods available on a string object. A method is a function that acts upon a specific object. Much like functions, methods are invoked, they can accept arguments, and they can return values. In this lesson, we introduce the find and index methods which return the lowest index in the string where a substring is found. We also discuss the differences between the two.
The startswith and endswith methods check for the inclusion of a substring at the beginning or end of a string. As always, case sensitivity matters. In this lesson, we practice invoking the two methods.
The count method returns an integer that represents the number of times a substring argument appears in a string. In this lesson, we discuss the semantics of this method, including what happens when the argument has more than 1 character.
See how to solve the problems in the previous coding challenge.
A string is bundled with several casing methods to convert it to lowercase, uppercase, and everything in between. All of these methods return a new string object. This lesson explores 5 of these methods and provides a quick review of immutability.
Methods on an object may return an object of a different type. In this lesson, we explore 7 methods on a string that test its characteristics (for example, the characters being all digits or all lowercase). These methods all return a Boolean value - True or False.
Whitespace at the beginning and end of strings is a common problem, especially when importing data from a file. In this lesson, we explore the lstrip, rstrip, and strip methods for solving this problem. The lstrip method removes whitespace from the beginning, the rstrip method from the end, and the strip method from both.
The replace method replaces all occurrences of a substring in a string. It accepts 2 arguments:
the substring to look for
the value to replace each substring with
Python strings are immutable; the method returns a new string with the substitutions.
See how to solve the problems in the previous coding challenge.
The format method injects or interpolates dynamic values, like variables, into an existing string. The format method was introduced in Python 3.0 and it returns a new string object. Arguments can be relative position, numeric position, or with keyword arguments.
Formatted string literals or f-strings are a new feature in Python 3.6 that allow for direct interpolation of variables or expressions into a string. Place an f or F before the start of the string. In this lesson, we practice this syntax with the mad libs example from the previous lesson.
Control flow refers to the order of execution in a program. We’re now going to expand into programs that have multiple paths of execution. We’re going to have code that may execute or may not execute based on a condition. In this lesson, we do a quick review of Booleans and thee equality / inequality operators, which will be critical in upcoming lessons.
A condition is an expression that evaluates to a Boolean value (True or False). The if statement uses a condition to determine whether a block of code will execute. In this lesson, we practice executing blocks of code conditionally.
In this lesson, we introduce truthiness, which refers to the state of an object being equivalent to True, and falsiness, which refers to the state of an object being equivalent to False. Zero and empty strings are examples of falsy objects. In this lesson, we explore how we can determine the truthiness of an object using the if statement or bool function.
See how to solve the problems in the previous coding challenge.
The else statement is a complement to the if statement. The else statement executes when the if statement evaluates to False. In this lesson, we write a program that asks the user for a numeric input, then shows them one of two outputs depending on their entry.
The elif statement can be used to test another condition after an if. Unlike the else statement, execution of some branch of logic is not guaranteed. In this lesson, we practice writing these multiple paths of code within a function.
See how to solve the problems in the previous coding challenge.
Python includes a shortcut for writing an if / else operation on a single line. It does not support the ternary operator, which is available in other languages.
The and keyword mandates that all conditions following the if keyword must evaluate to True for the code block to execute. In this lesson, we write a program validating a user's submission of both a username and a password.
The or keyword mandates that at least one of several conditions has to be true for the code block to execute. In this lesson, we dive into a few examples and demonstrate how Python evaluates these expressions behind the scenes.
The not keyword negates an expression. In other words, it returns the inverse of a Boolean value. In this lesson, we apply the keyword to several conditional expressions.
if statements can be nested within code blocks for other if statements. This allows us to create a structured sequence of logic to communicate what our code is doing.
See how to solve the problems in the previous coding challenge.
In this lesson, we begin our exploration of iteration with the while loop. A simply way to describe an iteration is a repetition. A while loop runs a block of code as long as a condition evaluates to True. We also discuss the dangers of an infinite loop, a loop that never ends and makes the program run out of memory.
Recursion is when a function calls itself. It's one of the most difficult concepts in programming but one that is remarkably powerful when used properly. In this lesson, we write a countdown example using a while loop, then show how it can also be done with recursion.
In this lesson, we continue practicing recursion by solving a string reversal problem. We begin with an iterative approach using a while loop, then show a compact 3-line solution using recursion.
See how to solve the problems in the previous coding challenge.
This section is dedicated to one of the most powerful data structures in programming, the list. A list is a data structures that stores an ordered sequence of objects. Each internal object is called an element. Lists are mutable objects, which means they are capable of change. Elements can be added to or removed from a list. Elements can also be replaced by other elements in the list. This lesson provides an overview of the syntax of declaring a list and populating it with items.
See how to solve the problems in the previous coding challenge.
In this lesson, we use the familiar in and not in keywords to check for inclusion and exclusion of an element in a list. Both of these operators return Booleans.
Much like each character in a string is assigned a position based on its place in line, every element in a list is assigned an index position. The index represents the order of the element within the list. In this lesson, we practice extracting single elements by both positive and negative index positions.
See how to solve the problems in the previous coding challenge.
Just like with a string, multiple elements can be extracted from a list with colon syntax. Provide a pair of square brackets after the list with a colon between two numbers. The lower bound (before the colon) is inclusive. The upper bound (after the colon) is exclusive.
See how to solve the problems in the previous coding challenge.
See how to solve the problems in the previous coding challenge.
Like a string, a list is an iterable Python object. An object is considered iterable if its elements can be stepped through one by one. In this lesson, we practice iterating over both of these objects using the for loop.
See how to solve the problems in the previous coding challenge.
The hardest challenge in programming is combining multiple ideas to solve problems. In this lesson, we'll explore how we can combine a for loop with a conditional to filter a list of values.
See how to solve the problems in the previous coding challenge.
The reversed function returns a special type of object called a generator object that can be iterated over. It is not a list but is list-like. In this lesson, we'll utilize reversed to flip around the elements in a list.
The enumerate function iterates over a list while keeping track of each element’s index position. The for loop thus requires two variables: the first one will represent the index and the second one will represent each element. In this lesson, we practice the syntax while iterating over a list of errands.
See how to solve the problems in the previous coding challenge.
The range function generates a collection of ordered numbers. Like a list, the range object also supports iteration with the for loop. range is a generator object: it yields one item at a time to the loop. In this explore, we explore the various arguments we can feed to range to represent the starting and ending range, as well as the optional step sequence.
The break keyword terminates a for loop before it reaches its natural conclusion. break is often paired with the if statement to leave the for loop based on a condition. In this lesson, we use break to check if a value exists anywhere within a list.
The continue keyword forces the for loop to move to the next iteration. The remainder of the block body is skipped for the current iteration. The continue is usually wrapped in a conditional. In this lesson, we write 2 different functions (one with continue, one without) to add the sum of positive numbers in a list.
In this lesson, we’ll explore how we can feed in arguments into a Python program from the command line (i.e. the Terminal or Command Prompt) The arguments will be bundled in a special list called argv, which is an acronym for argument variable). We can access argv as an attribute on the sys module, which has to be imported into our file.
Student Testimonials:
The course is extremely well organized with tons of great explanations and exercises for each and every topic imaginable! The instructor is a very good teacher, and gives great feedback, while rapidly answering any questions you may have. Highly recommend the course to anyone interested in Python or programming in general. - Sathvik H.
The most comprehensive and personalized learning experience in a programming course. Highly recommend to anyone interested, regardless of experience! - Danny N.
The instructor is great. Everything is really well explained. Appropriate for complete beginners as a intro to programming if that is needed. Also good if you are coming from other languages. The instructor also speaks super clearly. - Jon
Learn to Code with Python is a comprehensive introduction to programming in Python, the most popular programming language in the world. Python powers codebases in companies like Google, Facebook, Pinterest, Dropbox, and more. It is used in a variety of disciplines including data science, machine learning, web development, natural language processing, and more.
Over more than 58 hours of video content, we'll tackle the language from A to Z, covering everything you need to know about Python to be an effective developer in 2020.
The course is jam-packed with:
58+ hours of video, with new content added frequently
FREE 300-page PDF study manual with all the code samples written throughout the course
60+ coding challenges that you can complete in your browser
40+ multiple-choice quizzes
35+ written assignments
Complete programming projects including Texas Hold-Em Poker
Learn to Code with Python is designed from the ground up to take you from novice to professional. Complete beginners are welcome; no prior experience is needed! Over 400+ videos, we'll work our way from language fundamentals to advanced features. Topics covered include...
Setup & Installation
Variables
Data types
Functions and Methods
Control Flow
Lists and tuples
Dictionaries
Sets
Modules
Decorators
Classes
Exception Handling
The Python Standard Library
Unit testing
Regular Expressions
Virtual Environments
Web Scraping
...and more!
Throughout the entire journey, I'll be coding alongside you step by step in the code editor. You'll also have the opportunity to test your knowledge through numerous coding challenges, quizzes, and written assignments.
Python holds a special place in my heart -- it was the first language I ever learned! I'm honored to be able to pass on years of knowledge to a new group of avid learners. Whether you are a novice who's never written a line of code before or an experienced developer looking to dive into a new language, there’s something for you to enjoy in Learn to Code with Python.
Thanks for checking out the course!