profile

Learn Data Science from Data School 📊

x = 43; x += 1; print(f"Tuesday Tip #{x}")

Published about 2 months ago • 1 min read

Hi Reader, happy Tuesday!

My recent tips have been rather lengthy, so I'm going to mix it up with some shorter tips (like today's). Let me know what you think! 💬


🔗 Link of the week

​A stealth attack came close to compromising the world's computers (The Economist)

If you haven't heard about the recent "xz Utils backdoor", it's an absolutely fascinating/terrifying story! In short, a hacker (or team of hackers) spent years gaining the trust of an open-source project by making helpful contributions, which eventually allowed them to smuggle a sophisticated, hidden exploit into the code.

Had a single developer at Microsoft not discovered the problem (in his spare time!), hackers would soon have gained secret access to hundreds of millions of computers, allowing them to steal private data from banks, governments, and more.

For more technical details, see this article from Ars Technica.


👉 Tip #44: Augmented assignment in Python

If you're new to Python (or programming in general), you might be confused by code like this:

x += 1

As long as x is a number, that code translates to:

x = x + 1

In other words, it's a concise way to increment the value of x by 1.

This is known as "augmented assignment," and there are actually a dozen other augmented assignment operators in Python. Here are the most common ones:

x -= 3 (translates to x = x - 3)

x *= 4 (translates to x = x * 4)

x /= 2 (translates to x = x / 2)

Under the hood, these statements call dunder methods such as __iadd__, __isub__, and so on, which means that their behaviors can be customized for different types of objects.

In case you're curious, the "i" in __iadd__ stands for "in-place" because it mutates the original object. As such, you may notice an unexpected behavior if you try to use these operations with Python lists.


👋 See you next Tuesday!

Did you like this week’s tip? Please forward it to a friend or share this link with your favorite online community. It really helps me out!

- Kevin

P.S. xkcd comes true (a reference to the link of the week)

Did someone AWESOME forward you this email? Sign up here to receive Data Science tips every week!

Learn Data Science from Data School 📊

Kevin Markham

Join 25,000+ aspiring Data Scientists and receive Python & Data Science tips every Tuesday!

Read more from Learn Data Science from Data School 📊

Hi Reader, I'm really proud of this week's tip because it covers a topic (data leakage) that took me years to fully understand. 🧠 It's one of those times when I feel like I'm truly contributing to the collective wisdom by distilling complex ideas into an approachable format. 💡 You can read the tip below 👇 or on my blog. 🔗 Link of the week Building an AI Coach to Help Tame My Monkey Mind (Eugene Yan) In this short post, Eugene describes his experiences calling an LLM on the phone for coaching:...

28 days ago • 4 min read

Hi Reader, Last week, I recorded the FINAL 28 LESSONS 🎉 for my upcoming course, Master Machine Learning with scikit-learn. That's why you didn't hear from me last week! 😅 I edited one of those 28 videos and posted it on YouTube. That video is today's tip, which I'll tell you about below! 👉 Tip #45: How to read the scikit-learn documentation In order to become truly proficient with scikit-learn, you need to be able to read the documentation. In this video lesson, I’ll walk you through the five...

about 1 month ago • 1 min read

Hi Reader, Today's tip is drawn directly from my upcoming course, Master Machine Learning with scikit-learn. You can read the tip below or watch it as a video! If you're interested in receiving more free lessons from the course (which won't be included in Tuesday Tips), you can join the waitlist by clicking here: Yes, I want more free lessons! 👉 Tip #43: Should you discretize continuous features for Machine Learning? Let's say that you're working on a supervised Machine Learning problem, and...

about 2 months ago • 2 min read
Share this post