@
Python Tip #299 (of 365): Return Boolean expressions directly. 🧵 Do this: def is_even(n): return n % 2 == 0 Not this: def is_even(n): if n % 2 == 0: return True else: return False #Python #DailyPythonTip
@
“The print function is handy for showing output at the terminal, but that's not its only use.” Read more 👉 https://pym.dev/print-features/ #Python
@
🗺️ October 26, 2026 5/5 countries in 6/13 guesses 🟢🟢🟡🟢🟢 whereabouts.earth/daily/ #Whereabouts https://whereabouts.earth/daily/
@
“Something to keep in mind is that sys.platform actually represents the operating system that your Python interpreter was built for, while platform.system() returns the operating system that your Python interpreter is currently running on.” Read more 👉 https://pym.dev/operating-system-checks/ #Python
@
Apparently there are 28 Pythagorean triple dates each century and we just missed celebrating the last one for the century (yesterday!). These 8 plus 20 permutations: 2005-04-03 2010-08-06 2013-12-05 2015-12-09 2017-08-15 2020-12-16 2025-07-24 2026-10-24 Better luck next century. https://pym.dev/p/2qpz6/
@
Python Tip #298 (of 365): When creating lots of class instances, save memory with __slots__. 🧵 class Point: __slots__ = ("x", "y", "z") def __init__(self, x, y, z): (self.x, self.y, self.z) = (x, y, z) #Python #DailyPythonTip
@
🗺️ October 25, 2026 5/5 countries in 5/13 guesses 🟢🟢🟢🟢🟢 whereabouts.earth/daily/ #Whereabouts https://whereabouts.earth/daily/
@
Python Tip #297 (of 365): Avoid making metaclasses if you can. 🧵 There's usually an easier tool for the job. Metaclasses customize the behavior of CLASSES the same way classes customize the behavior of their instances. #Python #DailyPythonTip
@
🗺️ October 24, 2026 5/5 countries in 6/13 guesses 🟡🟢🟢🟢🟢 whereabouts.earth/daily/ #Whereabouts https://whereabouts.earth/daily/
@
“I find that I very rarely need the random function, because I often need random integers, not random floating point numbers.” Read more 👉 https://pym.dev/random-numbers/ #Python
@
Python Tip #296 (of 365): Always use functools.wraps when making a decorator. 🧵 A decorator REPLACES a decorated function with the function that was returned from calling the decorator. #Python #DailyPythonTip
@
🗺️ October 23, 2026 5/5 countries in 8/13 guesses 🟢🟢🟡🟠🟢 whereabouts.earth/daily/ #Whereabouts https://whereabouts.earth/daily/
@
“Another reason I tend to avoid implicit string concatenation is that it can sometimes cause bugs by accidentally using it.” Read more 👉 https://pym.dev/implicit-string-concatenation/ #Python
@
Python Tip #295 (of 365): Avoid needless deep copying. 🧵 Often a deepcopy call can be replaced by a comprehension, a slice, or some other operation that makes new objects. When you copy a list of dictionaries, you get a NEW list pointing to the SAME dictionaries. #Python #DailyPythonTip
@
🗺️ October 22, 2026 5/5 countries in 6/13 guesses 🟢🟢🟡🟢🟢 whereabouts.earth/daily/ #Whereabouts https://whereabouts.earth/daily/
@
Python Tip #294 (of 365): Use exceptions to pass error messages to users. 🧵 Catch exceptions with messages users shouldn't see, and raise your own with a message they SHOULD see: class WeatherError(Exception): """Raised when we can't show the user a forecast.""" #Python #DailyPythonTip
@
Python Tip #293 (of 365): Write context managers with contextlib.contextmanager. 🧵 Instead of making a class with __enter__ and __exit__ methods, we can make a context manager out of a function: #Python #DailyPythonTip
@
This was definitely the most islandful daily ever 🏝️ Whereabouts Daily 🗺️ October 20, 2026 5/5 countries in 5/13 guesses 🟢🟢🟢🟢🟢 whereabouts.earth/daily/ #Whereabouts https://whereabouts.earth/daily/
@
“This will allow us to close the file and then pass the temporary file's filename to wherever it needs to be, and then when the context manager exits, the file will be deleted automatically:” Read more 👉 https://pym.dev/temporary-files/ #Python
@
Python Tip #292 (of 365): Keep "try" blocks small with an "else" clause. 🧵 try: count = int(text) except ValueError: print("That's not a number") else: print(f"Counting to {count}") #Python #DailyPythonTip
@
🗺️ October 19, 2026 5/5 countries in 5/13 guesses 🟢🟢🟢🟢🟢 whereabouts.earth/daily/ #Whereabouts https://whereabouts.earth/daily/
@
Python Tip #291 (of 365): Check regex matches with the walrus operator. 🧵 Do this: if match := UNITS_RE.search(string): return match.groups() Not this: match = UNITS_RE.search(string) if match: return match.groups() #Python #DailyPythonTip https://pym.dev/using-walrus-operator/
@
“Using __slots__ can save memory because each instance of your class won't use a dictionary to store its attributes.” Read more 👉 pym.dev/__slots__/ #Python https://pym.dev/__slots__/
@
If anyone is curious about the polar opposite of this (bizarre) viewpoint, look up Georgism [contains quote post or other embedded content]
@
🗺️ October 18, 2026 5/5 countries in 6/13 guesses 🟢🟢🟢🟡🟢 whereabouts.earth/daily/ #Whereabouts https://whereabouts.earth/daily/
@
“But this fuzziness is consistent with Python's embrace of duck typing.” Read more 👉 https://pym.dev/class-or-function/ #Python
@
Python Tip #290 (of 365): Pretty-print data structures with pp. 🧵 >>> from pprint import pp >>> pp(user) {'name': 'Trey', 'languages': ['Python', 'JavaScript'], 'address': {'city': 'San Diego', 'state': 'CA'}} #Python #DailyPythonTip
@
🗺️ October 17, 2026 5/5 countries in 6/13 guesses 🟢🟢🟡🟢🟢 whereabouts.earth/daily/ #Whereabouts https://whereabouts.earth/daily/
@
“NotImplemented is basically a way to signal to Python: I don't know how to perform this operation, go ask the other object instead.” Read more 👉 https://pym.dev/when-to-use-notimplemented/ #Python