All chapters and sections
Chapter 0 · 39 questions Start Here
Chapter 1 · 54 questions Your First Program
Chapter 2 · 53 questions Values and Types
- 2.1Values: the things programs work with
- 2.2Asking for the type:
type() - 2.3Integers:
int - 2.4Floating-point numbers:
float - 2.5Text:
str - 2.6True or false:
bool - 2.7Nothing at all:
None - 2.8Complex numbers:
complex - 2.9Mixing types in a calculation
- 2.10Same value, different spellings
- 2.11How Python stores values
- +Practice
Chapter 3 · 54 questions Variables and Names
- 3.1Giving a value a name
- 3.2How assignment works
- 3.3Using variables
- 3.4Changing a variable
- 3.5Variables are labels, not boxes
- 3.6Dynamic typing
- 3.7Rules for names
- 3.8Naming conventions
- 3.9Don't reuse built-in names
- 3.10Several assignments at once
- 3.11Updating a variable:
+=and friends - 3.12Deleting a name:
del - 3.13Constants
- 3.14The shell's underscore
- 3.15What happens in memory
- +Practice
Chapter 4 · 53 questions Operators and Expressions
- 4.1Expressions
- 4.2Arithmetic operators
- 4.3Two kinds of division
- 4.4The remainder operator:
% - 4.5Powers:
** - 4.6The type of an expression
- 4.7Built-in number functions
- 4.8Assignment operators
- 4.9Bitwise operators
- 4.10Precedence: what's done first
- 4.11Operators on text
- 4.12What Python does with an operator
- +Practice
Chapter 5 · 55 questions Comparisons, Logic and Truthiness
- 5.1Asking a question: comparison operators
- 5.2Comparing numbers
- 5.3Comparing strings
- 5.4Comparing different types
- 5.5Chained comparisons
- 5.6Combining answers:
and,or,not - 5.7Short-circuit evaluation
- 5.8Truthiness
- 5.9What
andandorreally give back - 5.10A very common bug
- 5.11Identity:
isandis not - 5.12Membership:
inandnot in - 5.13How Python does logic
- +Practice
Chapter 6 · 58 questions Input and Type Conversion
- 6.1Asking the user:
input() - 6.2
input()always gives you text - 6.3Text to whole number:
int() - 6.4Text to decimal number:
float() - 6.5Numbers to text:
str() - 6.6Anything to true or false:
bool() - 6.7Converting between number types
- 6.8Reading other number bases
- 6.9What Python converts for you, and what it never does
- 6.10Several values on one line
- 6.11Cleaning up what the user typed
- 6.12Looking before you convert
- 6.13Built-in functions
- 6.14Common mistakes
- 6.15Putting it together
- 6.16How input and conversion work
- +Practice
Chapter 7 · 60 questions Strings I: Making Strings
- 7.1What a string is
- 7.2Single quotes and double quotes
- 7.3Escape sequences
- 7.4Strings over several lines: triple quotes
- 7.5Raw strings
- 7.6Measuring a string:
len() - 7.7Joining strings:
+ - 7.8Repeating strings:
* - 7.9Comparing and searching, briefly
- 7.10A first look at f-strings
- 7.11Strings cannot be changed
- 7.12Two ways to show a value:
str()andrepr() - 7.13Common mistakes
- 7.14Putting it together
- 7.15How Python stores strings
- +Practice
Chapter 8 · 60 questions Strings II: Indexing and Slicing
- 8.1Every character has a position
- 8.2Counting from the end: negative indexes
- 8.3Going out of range:
IndexError - 8.4Slicing: taking a piece
- 8.5Leaving numbers out
- 8.6Negative numbers in slices
- 8.7Slices never raise an error
- 8.8The third number: step
- 8.9You cannot change a character
- 8.10Everyday recipes
- 8.11Common mistakes
- 8.12Putting it together
- 8.13How indexing and slicing work
- +Practice
Chapter 9 · 60 questions Strings III: String Methods and Unicode
- 9.1What a method is
- 9.2Changing case
- 9.3Trimming the ends
- 9.4Searching inside a string
- 9.5Replacing
- 9.6Asking what a string contains
- 9.7Splitting and joining
- 9.8Lining text up
- 9.9Chaining methods
- 9.10Characters are numbers: Unicode
- 9.11From characters to bytes: encoding
- 9.12When equal-looking strings are not equal
- 9.13Finding the method you need
- 9.14Common mistakes
- 9.15Putting it together
- 9.16How methods and Unicode work
- +Practice
Chapter 10 · 58 questions Errors and Debugging
- 10.1Three kinds of error
- 10.2Reading a traceback
- 10.3A gallery of syntax errors
- 10.4A gallery of exceptions
- 10.5Logic errors: the silent kind
- 10.6A method for fixing any bug
- 10.7Tools for finding the bug
- 10.8The debugger
- 10.9Surviving an error: a first look at
tryandexcept - 10.10Asking for help well
- 10.11Common mistakes when debugging
- 10.12Putting it together
- 10.13How errors work inside Python
- +Practice
Chapter 11 · 60 questions Decisions: if, elif, else
- 11.1The
ifstatement - 11.2Indentation is the grammar
- 11.3Two paths:
else - 11.4Many paths:
elif - 11.5A chain or separate
ifs? - 11.6Decisions inside decisions: nesting
- 11.7Writing good conditions
- 11.8A decision in one line: the conditional expression
- 11.9The variable that might not exist
- 11.10An empty block:
pass - 11.11Patterns you will use again and again
- 11.12Common mistakes
- 11.13Putting it together
- 11.14How
ifworks inside Python - +Practice
Chapter 12 · 59 questions Pattern Matching: match and case
- 12.1Why
matchexists - 12.2The parts of a
match - 12.3Matching exact values
- 12.4Capturing: a pattern can give you a value
- 12.5Guards: a pattern plus a condition
- 12.6Matching the shape of data
- 12.7Matching by type
- 12.8A glimpse of what else patterns can do
- 12.9
matchorif? - 12.10Common mistakes
- 12.11Putting it together
- 12.12How
matchworks inside Python - +Practice
Chapter 13 · 61 questions while Loops, break and continue
- 13.1Why we need loops
- 13.2The
whilestatement - 13.3The condition is only checked at the top
- 13.4Infinite loops
- 13.5The standard patterns
- 13.6Loops that depend on the user
- 13.7Leaving early:
break - 13.8Skipping ahead:
continue - 13.9Assigning inside the condition: the walrus
- 13.10Taking a number apart
- 13.11Off by one
- 13.12A float is a poor loop counter
- 13.13A brief look ahead:
elseon a loop - 13.14Common mistakes
- 13.15Putting it together
- 13.16How a loop works inside Python
- +Practice
Chapter 14 · 60 questions for Loops and range
Chapter 15 · 61 questions Nested Loops and the Loop else
- 15.1A loop inside a loop
- 15.2Staying on the same line
- 15.3Rows and columns
- 15.4When the inner loop depends on the outer loop
- 15.5Every pair
- 15.6
breakin a nested loop - 15.7The
elseof a loop - 15.8Mixing
forandwhile - 15.9How much work is a nested loop?
- 15.10Common mistakes
- 15.11Choosing the right loop: a summary
- 15.12Putting it together
- 15.13How nested loops work inside Python
- +Practice