Python Morsels
Develop a more Pythonic coding style in as little as 30 minutes a week. Python Morsels includes exercises, screencasts, articles, and Daily Recall practice by a professional Python trainer.
- Posts
- 325 from 15 May 2020 to 26 Oct 2026
- Posting
- weekly (34 in the last year)
- Kind
- company blog
- Feed
- https://www.pythonmorsels.com/topics/feed/
2026 30
- f-string formatter
- strptime
- Feature History
- Python 3.15's best new features
- View All Screencasts →
- Read All Articles →
- Slicing lazy iterables with islice New
- Creating temporary files in Python
- When to use NotImplemented
- Goose typing New
- Quacking like a mapping New
- Binary search in Python with bisect
- Running subprocesses in Python
- Stacks and queues in Python
- Selecting random values in Python
- What types of exceptions should you catch?
- The list extend method
- Assigning to slices
- Standard error
- Making friendly classes
- Invent your own comprehensions
- When are classes used in Python?
- Lexicographical ordering
- Setting default dictionary values
- switch-case in Python? It's not match-case!
- Is it a class or a function?
- All iteration is the same
- Self-concatenation
- Debugging with f-strings
- Implicit string concatenation
2025 44
- Embrace whitespace
- Wrapping text output
- Unnecessary parentheses
- __slots__ for optimizing classes
- __dict__: where Python stores attributes
- T-strings: Python's Fifth String Formatting Technique?
- Since when?
- Python 3.14's best new features
- Why splitlines() instead of split("\n")?
- Nested list comprehensions
- Python REPL Shortcuts & Features
- Removing list items
- The power of Python's print function
- Checking your operating system
- Checking for string prefixes and suffixes
- Re-raising exceptions
- Using dictionaries
- Nested functions
- Don't call dunder methods
- Decorators with optional arguments
- Breaking out of a loop
- Python's "while" loop
- Equality with data structures
- Decorators can return anything
- Avoid indexes
- Enclosing scope
- Looping in reverse
- Common decorators included with Python
- Sorting iterables
- Practical uses of sets
- Mutable default arguments
- Unpacking arbitrary keyword arguments into a function call
- Checking whether iterables are equal
- Refactoring long boolean expressions
- Alternatives to Python's "break" statement
- The features of Python's help() function
- Multiline strings
- Avoid over-commenting
- Newlines and escape sequences
- Python Terminology
- datetime arithmetic
- Python's range() function
- Uppercasing and lowercasing
- The benefits of trailing commas
2024 44
- Merging dictionaries
- Storing attributes on functions
- Python's pathlib module
- Inspecting objects
- Customizing dataclass fields
- Customizing dataclass initialization
- Python 3.13's best new features
- Converting a string to a datetime
- The string split method
- Prompting a user for input
- Understanding help()
- Boolean operators
- Commenting
- Creating Python programs
- Functions and Methods
- Arithmetic
- Checking for an empty list
- Customizing dataclasses with arguments
- How to make a tuple
- What are dataclasses?
- Using "else" in a comprehension
- What are lists in Python?
- Strings
- Python's getattr function
- Data structures contain pointers
- Python's __setattr__ method
- Python's many command-line utilities
- Equality versus identity
- Assignment vs. Mutation
- Supporting containment checks
- Variables are pointers
- Overloading all attribute lookups: __getattribute__ versus __getattr__
- Multiline comments
- Python Big O: the time complexities of different data structures
- Python's http.server module
- Unnecessary else statements
- Every dunder method
- Python list slicing (with examples)
- The contextmanager decorator
- Arithmetic Dunder Methods
- The list insert method
- TextIOWrapper‽ converting files to strings
- None
- Using the Python REPL
2023 41
- Chained comparisons
- zip with different length iterables
- Descriptors
- Inspect modules interactively
- Working with JSON data
- Solving programming exercises
- Booleans are integers
- Reading from standard input
- Python's lambda functions
- What are metaclasses?
- Python's assert statement
- Are dictionaries ordered in Python?
- What is recursion?
- Python's range is a lazy sequence
- Using "else" with a loop
- Reserved words
- Creating a context manager
- Using attributes on classes
- Python's next() function
- The difference between return and print
- Django June 2023: Tips & Discussions
- Counting occurrences in Python with collections.Counter
- Fixing circular imports
- Substrings in Python: checking if a string contains another string
- How to assign a variable
- Short-circuit evaluation
- Dynamically importing modules
- How to make a sequence
- Python's any() and all() functions
- Implementing slicing
- What is a context manager?
- Function overloading
- Remove duplicates from a list
- Looping over dictionaries
- Python's list constructor: when and how to use it
- What is a mapping?
- Writing a CSV file
- Conditional operators
- Reading a CSV file
- Removing a dictionary key
- Singletons
2022 54
- Python's "if" statement
- Dynamically evaluating code
- List containment checks
- Python's ternary operator
- breakpoint: debugging
- SyntaxError: invalid syntax
- How does file buffering work?
- What does // mean in Python?
- Unindent multiline strings in Python with dedent
- Installing Python packages with pip
- Fixing TypeError: can only concatenate str (not "int") to str
- reduce() in Python and why to avoid it
- Creating a mapping
- What's __init__.py?
- Python's String Methods
- How not to use super
- When should you call super?
- Title-case a String
- Using pip requirements files
- Using virtual environments
- How I made a dataclass remover
- Appreciating Python's match-case by parsing Python code
- Python's setattr function and __setattr__ method
- When is equality the same as identity?
- Catching all exceptions
- Callables: Python's "functions" are sometimes classes
- Seeking in files
- Reading binary files
- File modes
- Flatten a list of lists
- Making hashable objects
- Unicode character encodings
- What is "hashable" in Python?
- Static methods
- Python f-string tips & cheat sheets
- Class methods
- How to make an iterator
- How to make an iterable
- What is an iterator?
- Built-in Functions
- How to create a generator function
- What is a generator function?
- Variables and objects
- Exiting a Python program
- Dunder variables
- Making the len function work on your Python objects
- Supporting index and key lookups
- How to remove spaces
- Catching multiple exception types
- What can you do with exception objects?
- How to raise an exception
- Python's try-except blocks
- dataclasses
- Deciphering Python's Traceback (most recent call last)
2021 75
- Representing binary data with bytes
- Overloading equality
- Converting datetime to UTC
- Making a lazy attribute
- Locally testing Python Morsels exercises
- Convert a list to a string
- Positional-only function arguments
- Unpacking iterables into iterables
- Unpacking iterables into function arguments
- Extended iterable unpacking
- Importing everything from a module
- Modules are cached
- File-like objects
- Printing to a file
- Write to a file
- Files are iterators
- Read a file line-by-line
- How to read from a text file
- Defining a main function
- Tuple unpacking isn't just for tuples
- Importing a module runs code
- Decorators aren't always functions
- Parsing command-line arguments
- Making a class decorator
- Accessing command-line arguments
- Python's walrus operator
- Raw strings
- Customizing what happens when you assign an attribute
- Making a read-only attribute
- Python's map and filter functions
- What can you do with generator expressions?
- Generators are iterators
- Turning a list comprehension into a generator expression
- How to write a generator expression
- Augmented assignments mutate
- Mutable tuples
- Module versus Script
- Making a decorator that accepts arguments
- Making a well-behaved decorator
- How to make a decorator
- What is a decorator?
- Passing functions as arguments to other functions
- The meaning of "callable"
- Mutating with an assignment statement
- When should you not use a list comprehension?
- Turning a for loop into a list comprehension
- Why use a list comprehension?
- Breaking up long lines of code
- Where does Python look for methods?
- Set and dictionary comprehensions
- List comprehensions
- 4 ways to import a module
- Making an auto-updating attribute
- The assignments hiding in your functions
- Does Python have constants?
- How attribute lookups and assignments work
- Truthiness
- Deep tuple unpacking
- Tuple unpacking
- Importing a module
- Assignment isn't just about the equals sign
- Inheriting one class from another
- Methods are just functions attached to classes
- Everything is an object
- Pass: Python's no-op
- Docstrings
- Attributes are everywhere
- What is __init__ in Python?
- Each module has its own global scope
- Scope is about assignment, not mutation
- String concatenation vs string interpolation
- Assigning to global variables
- Local and global variables
- Customizing the string representation of your objects
- Dunder methods
2020 20
- Python's 2 different string representations
- Python's self
- Classes are everywhere
- What is a class?
- Accepting arbitrary keyword arguments
- Keyword-only function arguments
- Sequences
- Accepting any number of arguments to a function
- How to make a function
- Positional vs keyword arguments
- How to call a function
- Python doesn't have type coercion
- Python's zip function
- Looping with indexes
- What is an iterable?
- Python's "for" loop
- String Representations for Classes
- The Iterator Protocol
- Duck Typing
- Zipping an Iterator to Itself
Undated 17
- Send Me Weekly Python Tips
- “I'm blown away by the usefulness of weekly exercises. There is nothing academic about them, and they seem to be applicable to many situations.” Volker Englisch Read full testimonial →
- Courses
- Python Resources
- Daily Recall
- Skill Levels
- All Tools
- Python Pastebin
- Online Python REPL
- undataclass
- Python Cheat Sheets
- Pricing
- Discounts
- Team Plans
- Redeem Code
- Get Your Employer to Pay
- Python Morsels vs LeetCode