Trey Hunner
banner
trey.io
Trey Hunner
@trey.io
Python & Django team trainer

I help folks sharpen their Python skills with https://PythonMorsels.com 🐍🍪

YIMBY. 95% vegan.
So when Python opens files, it normalizes all line endings to simply be represented as line feed characters (\n). Read more �‘‰ https://trey.io/ca0qyn #Python
trey.io
January 13, 2026 at 12:12 AM
Python Tip #12 (of 365):

Use "[]" to create empty lists instead of calling "list()". 🧵

(This week's tips will all be related to lists)

#Python #DailyPythonTip
January 12, 2026 at 7:04 PM
Python Tip #11 (of 365):

Avoid comparing to True and False in Python. 🧵

#Python #DailyPythonTip
January 11, 2026 at 3:18 PM
Python Tip #10 (of 365):

When checking for emptiness (or non-emptiness) in Python, use truthiness. 🧵

Instead of this:
if len(items) > 0:
...

Or this:
if len(items):
...

Do this:
if items:
...

#Python #DailyPythonTip
January 10, 2026 at 7:04 PM
I made a goal to share one #Python tip every day in 2026.

Based on the roll that Reuven's been on, I suspect he has a similar goal!

If you've been enjoying my tips, check out his as well!

We're definitely going to overlap many common tips, but there's no harm in seeing the same tip twice!
Use parentheses to split long #Python code across lines:

if x == 10 and
y == 20:
print('Yes!') # ☹️

But with parentheses, Python sees it as one line:

if (x == 10 and
y == 20): # 🙂
print('Yes!')

Or in comprehensions…

[x*5
for x in range(10)
if x % 2]
January 10, 2026 at 4:42 PM
Python Tip #9 (of 365):

When checking for None in Python, use identity instead of equality. 🧵

Use "result is None" instead of "result == None".

Using identity works because Python's None is a sentinel value, meaning there's exactly one None object in Python.

#Python #DailyPythonTip
January 9, 2026 at 4:05 PM
The hard part is figuring out which format string you need to specify to parse your date string properly. Read more �‘‰ https://trey.io/l4b84k #Python
January 9, 2026 at 1:06 AM
Python Tip #8 (of 365):

Use De Morgan's Law to make more readable Boolean expressions. 🧵

De Morgan's Law states that:

- "not (A or B)" is the same as "(not A) and (not B)"
- "not (A and B)" is the same as "(not A) or (not B)"

#Python #DailyPythonTip
January 8, 2026 at 3:04 PM
Speaking of the json module's command-line interface, you can now run it with python-m json instead of python-m json.tool Read more �‘‰ https://trey.io/flfwr9 #Python
trey.io
January 7, 2026 at 7:19 PM
Python Tip #7 (of 365):

Avoid using "or" short-circuiting for fallback reassignments. 🧵

Instead of this:

name = name or "world"

I recommend this:

if not name:
name = "world"

That second approach is more verbose, but I also find it more readable at a glance.

#Python #DailyPythonTip
January 7, 2026 at 7:04 PM
Python Tip #6 (of 365):

Use short-circuiting to collapse nested "if" statements. 🧵

These nested "if" statements:

if result:
if result.success:
print("success!")

Can instead be written with a single "if":

if result and result.success:
print("success!")

#Python #DailyPythonTip
January 6, 2026 at 5:21 PM
I'm surprised that golf courses use almost as much water as livestock. 😦
On AI & water, it looks like all US data center usage (not just AI) ranges from 628M gallons a day (counting evaporation from dam reservoirs used for hydro-power) to 200-275M with power but not dam evaporation, to 50M for cooling datacenters alone.

So not nothing, but also a lot less than golf.
January 6, 2026 at 1:30 AM
Python Tip #5 (of 365):

Use sensible chained comparisons in Python, like a < b < c 🧵

#Python #DailyPythonTip
January 5, 2026 at 7:04 PM
Python Tip #4 (of 365):

If you're debugging with print() calls, use a self-documenting expression in an f-string. 🧵

A self-documenting expression involves putting an = sign at the end of a replacement field:

>>> n = 256
>>> print(f"DEBUGGING {n**2=}")
DEBUGGING n**2=65536

#Python #DailyPythonTip
January 4, 2026 at 5:49 PM
A few weeks ago, I had an idea for an animal cruelty offset calculator that shows how underfunded the animal welfare space is, shows the current (huge) impact of $1 today, and encourages donations to specific charities based on lifestyle.

It turns out, this already exists! It's called FarmKind.
Offset your diet's impact on animals - FarmKind
What does it cost to help animals through donations as much as the average diet harms them through factory farming? Our compassion calculator helps you estimate this. You can even customize it based o...
www.farmkind.giving
January 3, 2026 at 9:12 PM
Python Tip #3 (of 365):

Learn about the common string formatting specifications. No need to memorize them, but learn which ones exist as it'll help you remember to look them up when you need them. 🧵

#Python #DailyPythonTip
January 3, 2026 at 7:04 PM
This was my first read of 2026 and I highly recommend it.

This book challenges liberals, conservatives, and various other groups to introspect the true reasons behind their thinking on immigration.

Also it's a comic book, which makes it more fun to read.
Open Borders: The Science and Ethics of Immigration by Bryan Caplan
An Economist "Our Books of the Year" Selection Economist Bryan Caplan makes a bold case for unres...
app.thestorygraph.com
January 3, 2026 at 5:26 PM
Python Tip #2 (of 365):

Prefer string interpolation over concatenation in all but simple cases. 🧵

#Python #DailyPythonTip
January 2, 2026 at 5:32 PM
Python Tip #1 (of 365):

Avoid implicit string concatenation. 🧵

In #Python, if two string literals are placed next to each other they will be implicitly concatenated.

These 2 are the same:

greeting = "Hello " "Trey"
greeting = "Hello" + "Trey"

I recommend avoiding this feature.

#DailyPythonTip
January 1, 2026 at 7:04 PM
May 2026 be the year we start the upswing toward a more communitarian society.

Go read The Upswing (and/or watch Join or Die on Netflix).
I've written up reviews for the books I most enjoyed reading in 2025 (all via audiobook).

My favorite fiction was @hankgreen.bsky.social's "An Absolutely Remarkable Thing" (and the sequel!).

I also really enjoyed 10 non-fiction books on immigration, economics, sociology, and animal welfare.
My favorite reads of 2025
I read 41 books this year, all via audiobook. Below are my reviews for my 13 favorite reads out of the 41 books I read. If you enjoy audobooks, I …
treyhunner.com
January 1, 2026 at 6:09 PM
we'll take a cup of kindness yet,
for auld lang syne
January 1, 2026 at 8:04 AM
Reposted by Trey Hunner
Our Solar System is orbiting the center of our Galaxy at about 220 km/s so in 2025 we collectively traveled something like 7 billion kilometers across the Milky Way. Once in a while, when you have a moment, it’s worthwhile to take a look around, see where you are, and appreciate how far you’ve come.
January 1, 2026 at 5:27 AM
I've written up reviews for the books I most enjoyed reading in 2025 (all via audiobook).

My favorite fiction was @hankgreen.bsky.social's "An Absolutely Remarkable Thing" (and the sequel!).

I also really enjoyed 10 non-fiction books on immigration, economics, sociology, and animal welfare.
My favorite reads of 2025
I read 41 books this year, all via audiobook. Below are my reviews for my 13 favorite reads out of the 41 books I read. If you enjoy audobooks, I …
treyhunner.com
December 31, 2025 at 9:11 PM
"All three of these functions are looping helpers, meaning they don't store their results anywhere." Read more �‘‰ https://trey.io/ur7l4g #Python
trey.io
December 31, 2025 at 12:12 AM
You could also try out using De Morgan's Law to see if distributing or un-distributing a negation might make your expression a little bit easier to read. Read more �‘‰ https://trey.io/f98u5c #Python
trey.io
December 30, 2025 at 12:12 AM