Ask me anything about your lessons or your code.
“What is a port?” · “Why is my code erroring?”
Python turns a plain-text file into running instructions, and the first useful instruction almost every program shares is printing text to the screen.
Your First Python Program
Python turns a plain-text file into running instructions, and the first useful instruction almost every program shares is printing text to the screen.
Variables and Types
A variable is a name Python attaches to a value, and the type of that value decides what the program is allowed to do with it.
Numbers and Math
Python does more than add and subtract: floor division, modulo, and exponents cover most of the math a real program needs, and knowing which operator gives an int versus a float saves a class of bugs.
Working with Strings
Text in Python lives in a string, and a string comes with its own toolkit: joining, formatting, cleaning, and picking apart characters by position.
Getting Input from the User
The input() function hands back a string no matter what was typed, and skipping the conversion to a number is the single most common beginner bug in Python.
Making Decisions with if
A Python program reads its input, compares values with booleans, and uses if, elif, and else to run different code depending on what it finds.
Repeating with Loops
A for loop repeats a fixed number of times over a range or a sequence, and a while loop repeats for as long as a condition holds, with break and continue changing how a single pass ends.
Lists: Many Values in One
A list holds many values under one name and in one order, and indexing, slicing, and looping are how a program reaches in and gets exactly what it needs.
Writing Functions
A function names a piece of logic once so a program can call it by that name instead of retyping the same lines everywhere they're needed.
Build a Small Program
A number-guessing game pulls every piece from this module, variables, strings, numbers, conditionals, loops, lists, and a function, into one program that actually runs.