Python Course — GameCode
Master Python from scratch in the kingdom of Pythoria, guided by the Wise Serpentia, an ancient guardian of knowledge. Learn variables, functions, lists, dictionaries and more through magical adventures.
Chapter 0: Your First Steps in Pythoria
Displaying Text on Screen with print()
Multiple print() Calls and Execution Order
Numbers and Operations in print()
Creating Strings with Single and Double Quotes
Comments with #
Chapter 1: The Seeds of Knowledge
Variables and Assignment
Numeric Types: int and float
Strings: Creating and Measuring with len()
Booleans: True and False
Type Conversion: int(), float(), str()
Reading User Input with input()
f-strings: Formatting Text
Assigning Multiple Variables in One Line
Project: Variables and Data Types
Chapter 2: The Written Scrolls
String Concatenation with +
Counting Characters in Strings with len()
Changing Case: upper() and lower()
Cleaning and Replacing Text: strip() and replace()
String Indexing
Extracting Text Fragments with Slicing
Finding and Counting Text: find() and count()
Splitting and Joining Text: split() and join()
f-strings with Expressions
Project: String Processing
Chapter 3: The Arithmetic of the Forest
Arithmetic Operators: +, -, *, /
Integer Division // and Modulo %
Exponents with **
Comparison Operators
Logical Operators: and, or, not
Compound Assignment Operators
Operator Precedence
Mixed Operations: int, float, and round()
Complex Math Expressions
Project: Calculator with Operators
Chapter 4: The Forks in the Path
Making Decisions with if
Two-Way Decisions: if and else
Multi-Way Decisions: if, elif, and else
Comparing Numbers and Strings in if
Combining Conditions with and/or in if
Nested Conditionals
Conditional Expressions (Ternary)
Type Checking with isinstance()
Comparing a value against several options: if/elif/else chains
Project: Classification System with Conditionals
Chapter 5: The River's Cycles
The for Loop: Iterating Over Lists
Repeating with for and range()
Repeating with a Condition: The while Loop
Controlling Loops with break and continue
Iterating Over Strings with for
Numbering Items While Iterating with enumerate()
Nested Loops
List Comprehension: Basic Syntax
Controlled Infinite Loop: while True and a Sentinel Value
Project: Combined Loops
Chapter 6: The Reusable Rituals
Functions: def and Calling
Parameters and Arguments
Returning Values from a Function with return
Default Parameters
Flexible Arguments with *args and **kwargs
Lambda Functions
Nested Functions and Closures
Modifying Functions with Decorators
Functions That Call Themselves: Recursion
Project: System with Functions
Chapter 7: The Forest Collections
Lists: Creating and Accessing
Modifying Lists: append(), insert(), remove(), and pop()
Extracting List Fragments with Slicing
Sorting Lists: sort() and sorted()
Creating Immutable Tuples
List Comprehension: Filtering and Transforming
Transforming and Filtering Lists: map() and filter()
Unpacking Lists and Tuples
Nested Lists
Project: Inventory with Lists
Chapter 8: The Ancestral Maps
Creating Dictionaries
Dictionaries: Accessing and Modifying
Getting Keys, Values, and Pairs: keys(), values(), and items()
Iterating Over Dictionaries with for
Creating Dictionaries with Dict Comprehension
Nested Dictionaries
Creating Unique Collections with Sets
Set Operations
Safe Dictionary Access: get() and setdefault()
Project: Nested Database
Chapter 9: The Final Trials of Pythoria
Project: Random Name Generator
Project: Inventory with Dictionaries
Project: Turn-Based Combat System
Project: Store with Discounts
Project: Caesar Cipher
Project: Data Statistics
Project: Interactive Text Adventure
Final Project: Character Creator
Chapter 10: The Guilds of Pythoria
Classes and objects: creating molds with class and __init__
Instance methods: what self is
Class attributes vs instance attributes
Showing objects as text: __str__ and __repr__
Inheritance: a child class that reuses with super()
Overriding methods and polymorphism
Properties with @property and validating setters
Class and static methods: @classmethod and @staticmethod
Project: an adventurers' guild with classes
Chapter 11: The Forges of Molds
Comparing objects: __eq__ and __lt__ to sort with sorted()
Objects that behave like collections: __len__, __getitem__ and __contains__
Your own operators: adding objects with __add__
Abstract classes with abc: forcing child classes to comply
Composition: objects that contain other objects
Encapsulation in Python: _protected and __private
dataclasses: data classes without writing __init__
Project: the blacksmith's shop with dataclasses and composition
Chapter 12: The Chamber of Errors
Reading an error: what an exception is and how to catch it with try/except
Catching the right error: several excepts by type
else and finally: what happens on success and what always happens
Raising your own errors with raise
Creating your own exceptions by inheriting from Exception
Validating data: asking forgiveness (try) or permission (if)
Context managers: with and contextlib.contextmanager
Project: an error-proof kingdom cash machine
Chapter 13: The Scribe's Archives
Writing and reading text files with open() and with
Open modes: write (w), append (a) and reading line by line
File paths with pathlib
JSON: saving and loading data with the json module
CSV: reading and writing tables with the csv module
File errors: FileNotFoundError and utf-8 encoding
Dates and times with datetime and timedelta
Project: an adventure journal saved in JSON
Chapter 14: The Higher Spells
Sorting by a rule: sorted(), min() and max() with key
Looping in parallel: zip() and dict(zip())
Asking the whole list: any() and all()
Comprehensions with conditions, nested and for sets
Functions that receive and return functions
Closures with memory: nonlocal
Real decorators: functools.wraps and decorators with arguments
Memory for slow functions: functools.lru_cache
Project: the tournament leaderboard
Chapter 15: The Endless Springs
Iterables and iterators: what for does inside with iter() and next()
Generators with yield: functions that hand out one at a time
Generator expressions: a comprehension in parentheses that saves memory
Creating your own iterator: __iter__ and __next__
Infinite generators and how to cut them: itertools.count and islice
itertools tools: chain, product, combinations and groupby
Project: processing the castle's logs in batches with generators
Chapter 16: The Libraries of Pythoria
Importing modules: import, from and import with an alias
if __name__ == "__main__": code that only runs as a program
Packages, pip and virtual environments
collections: Counter, defaultdict, namedtuple and deque
Finding patterns in text with regular expressions (re)
Type annotations: List, Dict, Optional and Tuple
Type contracts: Union, Callable, TypedDict and Protocol
Project: the kingdom's report analyzer with collections and re
Chapter 17: The Guardians of Quality
Checking that code works with assert
doctest: examples inside the documentation that test themselves
unittest: your first test class with TestCase
More assertions: assertRaises, assertIn and assertAlmostEqual
Preparing each test with setUp and independent tests
Faking pieces with unittest.mock: patching random and input
Project: writing the tests first (TDD) for the inventory