For Black Friday, why not buy yourself a bunch of Python skills? You can't really do that, but you CAN buy yourself a commitment to learn Python. My new Python Jumpstart course is 50% off today. 💸 #Python #BlackFriday
When the first line in a function is a string all on its own, Python reads that string as documentation, and it stores that docstring on the function, so that tools like help can find it. Read more 👉 #Python
What's in a name? That which we call a duck By any other name would quack the same; So a sequence would, were it not a sequence call'd, Retain that dear iterability which it bears Without that title. Sequence, doff thy name, And for that name which is no part of thee give thy iterator to me. #Python #DuckTyping
Most Intro to Python courses consist of 2 hours of lectures and 2-10 exercises. My new Python Jumpstart course is different. It's dozens of very short videos, each followed by an exercise. You'll watch/read something new for 4 minutes and immediately try it out yourself. This new course is 50% off through Monday. #Python
Avoid unnecessary sorting in Python. ❌ Instead of this: smallest = sorted(items)[0] ✅ Do this: smallest = min(items) ❌ Instead of this: smallest = sorted(items)[:3] ✅ Do this: import heapq smallest = heapq.nsmallest(3, items) Why avoid sorting? 1. Performance: min is O(n), nsmallest is O(n log k), sorted is O(n log n) 2. Readability: min & nsmallest note what we really want our code to do For more on the performance of various operations in #Python, see
Data structures don't contain objects, they contain pointers to objects. Read the full article: Data structures contain pointers ▸ #Python
Trouble learning Python? 🐍 You need active recall and spaced repetition. 🧠 In other words, attempt to write code yourself to apply each new concept you visit and do this repeatedly over many days. Most Intro to Python courses consist of a series of lectures. 📺 Good lectures can be a lot of fun, but they do very little to help making learning stick. That's why my new Python Jumpstart course is 90% exercise-driven. #Python
In Python, instead of this: BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) I prefer this: BASE_DIR = pathlib.Path(__file__).resolve().parent.parent For more on the magic of Python's pathlib module, check out the article I published last week: #Python #pathlib
Python's list comprehensions and if-else Read more 👉 #Python