Just a cute pic of me
by Mike McKee
Programming

A Major Programming Milestone

66 Days of Math and Programming -- Day 28

I feel like a freaking genius. I’m at a stage in my Python journey where I know I’ve learned a lot.

Yesterday I made a simple tweak to a piece of my code that’s nothing for an experienced Python developer but means the world to me.

What did I do?

I used the *args method for the first time on my own.

I didn’t need Google or ChatGPT to help me optimize my code. I did it all on my own.

Here’s the function I optimized with *args...

Python code using *args

So, how did I decide to use this method instead of leaving the function to take one argument?

After doing some testing, I needed to update my database and revert statuses from 0 to 1. But that involved an annoying and repetitive call that looked like this…

how to call my function without *args

And while I’m usually only changing one value at a time when I use this code in the real world, there will be a lot of times I’m trying to change multiple (non-sequential) values at the same time.

So switching to the *args method makes my calling code look like this…

How to call my function with *args

Again, none of this is super advanced code that only a pro could do.

It’s a basic method that helps you optimize code.

But being able to practically use this and notice when to use this strategy in the real world is making me realize I’m learning a lot.

And in turn, I’m becoming a more confident programmer.