Get the Current Date and Time in Python (datetime.now)

Current date and time in Python: the Command Prompt showing the DeprecationWarning raised by datetime.utcnow in Python 3.12

datetime.now() is how Python hands you the current date and time, in a single object: For the date on its own, date.today() is shorter. To control how it looks, pass a pattern to strftime(). One thing has changed recently and is worth knowing: datetime.utcnow() is deprecated. The replacement is covered below, along with formatting, timezones … Read more >>

How to Iterate Through Tuples in Python (6 Methods with Examples)

loop through tuple python

Tuples are everywhere in Python: database query results, function return values, coordinate pairs, and configuration settings. And knowing the right way to loop through them can make your code cleaner, faster, and more Pythonic. To iterate through a tuple in Python, you can use a for loop, a while loop, enumerate(), zip(), list comprehension, or itertools.chain(), each suited for a different scenario. … Read more >>

How to Append to a Tuple in Python (5 Methods with Examples)

Append to a Tuple in Python

Every Python developer hits this wall at some point. You have a tuple, you need to add an element to it, and Python throws back a cold AttributeError: ‘tuple’ object has no attribute ‘append’. Frustrating? Absolutely. But it’s fixable, and once you understand why tuples work the way they do, the solution makes complete sense. In this guide, … Read more >>

Python dataclass vs namedtuple: Which Should You Use?

Python dataclass vs namedtuple

If you’ve ever returned structured data from a function or tried to group related values cleanly, you’ve probably run into both namedtuple and dataclass. They look similar on the surface; both let you create objects with named fields, but they’re built for different jobs. I get this question a lot in Python training sessions: “When do I use one … Read more >>

How to Use loc in Pandas

loc in Pandas

I have spent over a decade building data-driven applications in Python. During that time, I’ve found that the loc property is the most versatile tool in the Pandas library. It is the primary way to access, filter, and even update your data using labels. If you are still struggling with data selection, this guide will … Read more >>

TensorFlow vs PyTorch: Which Should You Learn?

TensorFlow and PyTorch

Let me be upfront with you: this isn’t a “both are great, it depends!” article. You’ve probably read a dozen of those already. I’m going to tell you what the data actually says, what the job market looks like right now, and then give you a clear recommendation based on where you’re headed. The short … Read more >>