The Curious Engineer

All blogs / Python

Python Morsels

pythonmorsels.com/topics

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.

Python

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

  1. f-string formatter
  2. strptime
  3. Feature History
  4. Python 3.15's best new features
  5. View All Screencasts →
  6. Read All Articles →
  7. Slicing lazy iterables with islice New
  8. Creating temporary files in Python
  9. When to use NotImplemented
  10. Goose typing New
  11. Quacking like a mapping New
  12. Binary search in Python with bisect
  13. Running subprocesses in Python
  14. Stacks and queues in Python
  15. Selecting random values in Python
  16. What types of exceptions should you catch?
  17. The list extend method
  18. Assigning to slices
  19. Standard error
  20. Making friendly classes
  21. Invent your own comprehensions
  22. When are classes used in Python?
  23. Lexicographical ordering
  24. Setting default dictionary values
  25. switch-case in Python? It's not match-case!
  26. Is it a class or a function?
  27. All iteration is the same
  28. Self-concatenation
  29. Debugging with f-strings
  30. Implicit string concatenation

2025 44

  1. Embrace whitespace
  2. Wrapping text output
  3. Unnecessary parentheses
  4. __slots__ for optimizing classes
  5. __dict__: where Python stores attributes
  6. T-strings: Python's Fifth String Formatting Technique?
  7. Since when?
  8. Python 3.14's best new features
  9. Why splitlines() instead of split("\n")?
  10. Nested list comprehensions
  11. Python REPL Shortcuts & Features
  12. Removing list items
  13. The power of Python's print function
  14. Checking your operating system
  15. Checking for string prefixes and suffixes
  16. Re-raising exceptions
  17. Using dictionaries
  18. Nested functions
  19. Don't call dunder methods
  20. Decorators with optional arguments
  21. Breaking out of a loop
  22. Python's "while" loop
  23. Equality with data structures
  24. Decorators can return anything
  25. Avoid indexes
  26. Enclosing scope
  27. Looping in reverse
  28. Common decorators included with Python
  29. Sorting iterables
  30. Practical uses of sets
  31. Mutable default arguments
  32. Unpacking arbitrary keyword arguments into a function call
  33. Checking whether iterables are equal
  34. Refactoring long boolean expressions
  35. Alternatives to Python's "break" statement
  36. The features of Python's help() function
  37. Multiline strings
  38. Avoid over-commenting
  39. Newlines and escape sequences
  40. Python Terminology
  41. datetime arithmetic
  42. Python's range() function
  43. Uppercasing and lowercasing
  44. The benefits of trailing commas

2024 44

  1. Merging dictionaries
  2. Storing attributes on functions
  3. Python's pathlib module
  4. Inspecting objects
  5. Customizing dataclass fields
  6. Customizing dataclass initialization
  7. Python 3.13's best new features
  8. Converting a string to a datetime
  9. The string split method
  10. Prompting a user for input
  11. Understanding help()
  12. Boolean operators
  13. Commenting
  14. Creating Python programs
  15. Functions and Methods
  16. Arithmetic
  17. Checking for an empty list
  18. Customizing dataclasses with arguments
  19. How to make a tuple
  20. What are dataclasses?
  21. Using "else" in a comprehension
  22. What are lists in Python?
  23. Strings
  24. Python's getattr function
  25. Data structures contain pointers
  26. Python's __setattr__ method
  27. Python's many command-line utilities
  28. Equality versus identity
  29. Assignment vs. Mutation
  30. Supporting containment checks
  31. Variables are pointers
  32. Overloading all attribute lookups: __getattribute__ versus __getattr__
  33. Multiline comments
  34. Python Big O: the time complexities of different data structures
  35. Python's http.server module
  36. Unnecessary else statements
  37. Every dunder method
  38. Python list slicing (with examples)
  39. The contextmanager decorator
  40. Arithmetic Dunder Methods
  41. The list insert method
  42. TextIOWrapper‽ converting files to strings
  43. None
  44. Using the Python REPL

2023 41

  1. Chained comparisons
  2. zip with different length iterables
  3. Descriptors
  4. Inspect modules interactively
  5. Working with JSON data
  6. Solving programming exercises
  7. Booleans are integers
  8. Reading from standard input
  9. Python's lambda functions
  10. What are metaclasses?
  11. Python's assert statement
  12. Are dictionaries ordered in Python?
  13. What is recursion?
  14. Python's range is a lazy sequence
  15. Using "else" with a loop
  16. Reserved words
  17. Creating a context manager
  18. Using attributes on classes
  19. Python's next() function
  20. The difference between return and print
  21. Django June 2023: Tips & Discussions
  22. Counting occurrences in Python with collections.Counter
  23. Fixing circular imports
  24. Substrings in Python: checking if a string contains another string
  25. How to assign a variable
  26. Short-circuit evaluation
  27. Dynamically importing modules
  28. How to make a sequence
  29. Python's any() and all() functions
  30. Implementing slicing
  31. What is a context manager?
  32. Function overloading
  33. Remove duplicates from a list
  34. Looping over dictionaries
  35. Python's list constructor: when and how to use it
  36. What is a mapping?
  37. Writing a CSV file
  38. Conditional operators
  39. Reading a CSV file
  40. Removing a dictionary key
  41. Singletons

2022 54

  1. Python's "if" statement
  2. Dynamically evaluating code
  3. List containment checks
  4. Python's ternary operator
  5. breakpoint: debugging
  6. SyntaxError: invalid syntax
  7. How does file buffering work?
  8. What does // mean in Python?
  9. Unindent multiline strings in Python with dedent
  10. Installing Python packages with pip
  11. Fixing TypeError: can only concatenate str (not "int") to str
  12. reduce() in Python and why to avoid it
  13. Creating a mapping
  14. What's __init__.py?
  15. Python's String Methods
  16. How not to use super
  17. When should you call super?
  18. Title-case a String
  19. Using pip requirements files
  20. Using virtual environments
  21. How I made a dataclass remover
  22. Appreciating Python's match-case by parsing Python code
  23. Python's setattr function and __setattr__ method
  24. When is equality the same as identity?
  25. Catching all exceptions
  26. Callables: Python's "functions" are sometimes classes
  27. Seeking in files
  28. Reading binary files
  29. File modes
  30. Flatten a list of lists
  31. Making hashable objects
  32. Unicode character encodings
  33. What is "hashable" in Python?
  34. Static methods
  35. Python f-string tips & cheat sheets
  36. Class methods
  37. How to make an iterator
  38. How to make an iterable
  39. What is an iterator?
  40. Built-in Functions
  41. How to create a generator function
  42. What is a generator function?
  43. Variables and objects
  44. Exiting a Python program
  45. Dunder variables
  46. Making the len function work on your Python objects
  47. Supporting index and key lookups
  48. How to remove spaces
  49. Catching multiple exception types
  50. What can you do with exception objects?
  51. How to raise an exception
  52. Python's try-except blocks
  53. dataclasses
  54. Deciphering Python's Traceback (most recent call last)

2021 75

  1. Representing binary data with bytes
  2. Overloading equality
  3. Converting datetime to UTC
  4. Making a lazy attribute
  5. Locally testing Python Morsels exercises
  6. Convert a list to a string
  7. Positional-only function arguments
  8. Unpacking iterables into iterables
  9. Unpacking iterables into function arguments
  10. Extended iterable unpacking
  11. Importing everything from a module
  12. Modules are cached
  13. File-like objects
  14. Printing to a file
  15. Write to a file
  16. Files are iterators
  17. Read a file line-by-line
  18. How to read from a text file
  19. Defining a main function
  20. Tuple unpacking isn't just for tuples
  21. Importing a module runs code
  22. Decorators aren't always functions
  23. Parsing command-line arguments
  24. Making a class decorator
  25. Accessing command-line arguments
  26. Python's walrus operator
  27. Raw strings
  28. Customizing what happens when you assign an attribute
  29. Making a read-only attribute
  30. Python's map and filter functions
  31. What can you do with generator expressions?
  32. Generators are iterators
  33. Turning a list comprehension into a generator expression
  34. How to write a generator expression
  35. Augmented assignments mutate
  36. Mutable tuples
  37. Module versus Script
  38. Making a decorator that accepts arguments
  39. Making a well-behaved decorator
  40. How to make a decorator
  41. What is a decorator?
  42. Passing functions as arguments to other functions
  43. The meaning of "callable"
  44. Mutating with an assignment statement
  45. When should you not use a list comprehension?
  46. Turning a for loop into a list comprehension
  47. Why use a list comprehension?
  48. Breaking up long lines of code
  49. Where does Python look for methods?
  50. Set and dictionary comprehensions
  51. List comprehensions
  52. 4 ways to import a module
  53. Making an auto-updating attribute
  54. The assignments hiding in your functions
  55. Does Python have constants?
  56. How attribute lookups and assignments work
  57. Truthiness
  58. Deep tuple unpacking
  59. Tuple unpacking
  60. Importing a module
  61. Assignment isn't just about the equals sign
  62. Inheriting one class from another
  63. Methods are just functions attached to classes
  64. Everything is an object
  65. Pass: Python's no-op
  66. Docstrings
  67. Attributes are everywhere
  68. What is __init__ in Python?
  69. Each module has its own global scope
  70. Scope is about assignment, not mutation
  71. String concatenation vs string interpolation
  72. Assigning to global variables
  73. Local and global variables
  74. Customizing the string representation of your objects
  75. Dunder methods

2020 20

  1. Python's 2 different string representations
  2. Python's self
  3. Classes are everywhere
  4. What is a class?
  5. Accepting arbitrary keyword arguments
  6. Keyword-only function arguments
  7. Sequences
  8. Accepting any number of arguments to a function
  9. How to make a function
  10. Positional vs keyword arguments
  11. How to call a function
  12. Python doesn't have type coercion
  13. Python's zip function
  14. Looping with indexes
  15. What is an iterable?
  16. Python's "for" loop
  17. String Representations for Classes
  18. The Iterator Protocol
  19. Duck Typing
  20. Zipping an Iterator to Itself

Undated 17

  1. Send Me Weekly Python Tips
  2. “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 →
  3. Courses
  4. Python Resources
  5. Daily Recall
  6. Skill Levels
  7. All Tools
  8. Python Pastebin
  9. Online Python REPL
  10. undataclass
  11. Python Cheat Sheets
  12. Pricing
  13. Discounts
  14. Team Plans
  15. Redeem Code
  16. Get Your Employer to Pay
  17. Python Morsels vs LeetCode