##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Explore individual topics with detailed lessons and practice problems.
Before writing code, understand what Python is and set up your environment. Install and run scripts.
The goal
Readable and powerful
Preview of skills
Write code in browser
Test the compiler
Your coding editor
For offline coding
File naming rules
Hello World
Execute the code
Hello World basics
Displaying output
Comma-separated values
Change the separator
Change line endings
Full control
sep and end
First program
Notes in your code
Practice exercise
Your first challenge
Test your knowledge
What's being asked
Writing the solution
summary
Exact output matters
Generating sequences
Custom starting point
Skip numbers
Number sequences
Use range()
Combining concepts
Key observation
The solution
summary
Key techniques
Reading user data
String to number
Reading several values
Reading data
Read and print
How to approach problems
Common structures
Matching expected output
Reading problems
Avoid these pitfalls
Debug faster
What we learned
Now that we can run code, we need a way to store information. This section teaches you how Python remembers things.
The goal
Storing data
The equals sign
Rules and conventions
Clarity matters
Naming rules
Different kinds of data
Whole numbers
Decimal numbers
Text data
True or False
Type identification
The type() function
Changing types
What can convert
Converting values
Read and multiply
Math in Python
Order of operations
Shorthand operators
Math operations
Add two numbers
HackerRank challenge
Breaking it down
The solution
summary
Input-process-output
Joining strings
Multiplying strings
The len() function
Accessing characters
String operations
Extracting substrings
Formatted strings
Calculations in strings
Built-in transformations
String formatting
Use f-strings
HackerRank challenge
Two types of division
The solution
summary
// vs /
Assigning several variables
Values that don't change
Representing nothing
None and constants
HackerRank challenge
The pattern
The solution
summary
What we learned
Programs that always do the same thing are boring. This section teaches your code how to choose different paths based on conditions.
The goal
Basic branching
Python's structure
Making comparisons
True or False results
Conditional syntax
Alternative path
One or the other
Alternative execution
Multiple conditions
Top to bottom checking
Chain of conditions
Check sign
HackerRank challenge
Breaking down the rules
The solution
summary
Checking divisibility
Combining conditions
All must be true
At least one true
Inverting conditions
Combining conditions
Check eligibility
Date logic challenge
The rules explained
The solution
summary
Parentheses matter
Conditions inside conditions
Using and/or instead
Efficiency in conditions
Evaluation order
One-line conditionals
Keep it simple
Compact conditionals
Score to grade
Classic interview question
Order of checks
The solution
summary
Most specific first
Alphabetical order
The in operator
is vs ==
== vs is
What we learned
Doing something once is easy. Doing it a thousand times by hand is impossible. This section teaches repetition.
The goal
Repeat while true
Loops that never stop
Interactive loops
Loop basics
Iterate over sequences
Counting loops
When to use which
Iteration basics
Descending loop
Loop practice
The accumulator pattern
The solution
summary
Loop aggregation
Exit loops early
Skip to next iteration
Exit vs skip
Loop control
While with break
Second highest value
Two approaches
The solution
summary
Removing duplicates
Loops inside loops
Nested loop example
Building shapes
Iteration counts
Nested loops
Nested loop challenge
The core idea
The solution
summary
Row relationships
Uncommon but useful
Found or not found
When else runs
Index and value together
Parallel iteration
Concise loop syntax
enumerate and zip
What we learned
A single variable holds one thing. But what if you have a hundred things? This section introduces Python's most important data structure.
The goal
Collections in Python
Building your first lists
Using index notation
Creating and accessing
Counting from the end
Counting elements
The in operator
Positive and negative
Extracting sublists
Skipping elements
Changing list values
Extracting portions
List indexing
Adding to the end
Adding multiple items
Adding at a position
append, extend, insert
Remove by value
Remove by index
Delete and empty
remove, pop, del
Ordering elements
Flipping order
index() and count()
sort, reverse, find
Sum elements
Loop through elements
Index and value together
Building lists concisely
Adding conditions
List building syntax
Max in list
Finding the largest value
Breaking down the approach
Writing the solution
Patterns learned
Try it yourself
Lists within lists
Multi-dimensional access
Avoiding shared references
Concatenation and repetition
List copies and operators
Eliminating repeated values
Tracking seen values
Writing the solution
Patterns learned
Try it yourself
Lists summary
You've been writing code inside loops. Now learn to organize it into reusable pieces. Functions let you write code once and use it anywhere.
Why functions matter
Core concept
The motivation
Understanding functions
The def keyword
Running your code
Syntax check
Function inputs
Values you pass
The difference
Input terminology
First function problem
The code
summary
Getting results back
The difference
Output mechanics
Your first function
Boolean functions
The code
summary
More inputs
Position matters
Order check
Two parameters
Optional arguments
Position requirement
Optional values
Named parameters
Ordering rules
Named calling
Using defaults
The code
summary
None return
The difference
Missing returns
Variable visibility
Inside functions
Outside functions
Modifying globals
Local vs global
Documenting functions
Best practices
Documentation check
Finding the larger
One-line functions
Appropriate cases
Anonymous functions
Classic function
The code
summary
Computing n!
Exit immediately
Different paths
Tuple unpacking
Return patterns
Two returns
Passing functions
Avoid these errors
What we learned
Lists use positions. But what if you want to look things up by name instead of number? Dictionaries let you store key-value pairs for instant lookup.
Why dictionaries matter
Core concept
Syntax options
Key-value pairs
Square bracket lookup
Safe access
Lookup methods
Changing entries
Deleting entries
Add and remove
First dictionary problem
The code
summary
The in operator
Get all keys
Get all values
Get key-value pairs
keys, values, items
Count occurrences
Dictionary for counting
summary
Count characters
The code
summary
String frequency
Dictionaries inside dictionaries
Deep lookups
Deep access
One-line dictionaries
Filtering entries
Dictionary building
Swap keys and values
The code
summary
Swap keys and values
Get or set
Organize by category
Category organization
Organize words
The code
summary
Merge dictionaries
zip() for pairing
Building and merging
Group by grade
Hashable types
Choosing the right tool
Avoid these errors
Classic algorithm problem
Dictionary approach
The code
summary
Find the pair
What we learned
You know lists and dicts. Now meet tuples (immutable sequences) and sets (unique collections).
Two new collection types
Immutable sequences
Parentheses syntax
Parentheses are optional
Single-element gotcha
Indexing like lists
Extracting portions
The restriction that helps
What tuples prevent
Build your first tuple
Grouping values together
Extracting values at once
The * operator
Variable assignment
Classic unpacking trick
Functions returning tuples
Tuple return practice
Using immutability
Choosing the right type
Unique elements only
Curly braces syntax
Use set(), not {}
Empty set creation
Unique and unordered
The add() method
remove() vs discard()
remove vs discard
Add without duplicates
The in operator
Entry problem for sets
Sets eliminate duplicates
The code
summary
Combining two sets
Elements in both sets
What's in A but not B
Elements in exactly one set
Intersection result
Union and intersection
Set intersection application
Intersection of character sets
The code
summary
Keep first occurrence only
Track seen elements
The code
summary
Find the first non-repeating
Count then scan
The code
summary
Immutable sets
list(), tuple(), set()
What conversion preserves
Convert and process
When sets are faster
Summary of when to use what
What we learned
You've written functions. Now learn functions that call themselves. Recursion solves divide-and-conquer.
Self-calling functions
Self-referential functions
Stopping condition
Breaking down the problem
Why recursion stops
Classic recursion example
Step-by-step solution
Implement factorial
How Python tracks calls
Understanding recursion depth
Second recursion pattern
Step-by-step solution
Implement digit sum
Key patterns so far
Recursion on sequences
Step-by-step solution
Implement string reversal
Two recursive calls
Step-by-step solution
Implement Fibonacci
Why naive fib is slow
Recursion with division
Fast exponentiation
Implement fast power
Counting with recursion
Step-by-step solution
Count digits recursively
Processing sequences
Test list pattern
Recursion to find max
Step-by-step solution
Find max recursively
Two-pointer recursion
Step-by-step solution
Check palindrome
Divide and conquer
Step-by-step solution
Implement binary search
Why binary search is fast
Passing state recursively
Optimization pattern
Identify tail recursion
Choosing the right tool
Avoiding recursion bugs
Converting between styles
Choose the right approach
Tracing and fixing bugs
Caching recursive results
Test recursion proficiency
What we learned