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 >>

Python 2 vs Python 3 — What Changed and Why You Should Upgrade

python 2 vs python

If you’re still running Python 2, or you’ve stumbled across old code that uses it, this guide is for you. I’ll walk through what actually changed between Python 2 and Python 3, why those changes matter in practice, and why upgrading isn’t optional anymore — it’s overdue. The Short Answer First Python 2 officially reached … Read more >>

Virtual Environments in Python (venv, pipenv, conda)

Virtual Environments Python

If you’ve been writing Python for a little while, you’ve probably heard someone say, “Just use a virtual environment.” But what does that actually mean, and why does it matter? In this guide, I’ll explain virtual environments in plain language, show you how to set one up using three popular tools, venv, pipenv, and conda, … Read more >>

Python zip() Function

zip() Function Python

The zip() function in Python lets you combine two or more iterables- lists, tuples, strings, or ranges- and iterate over them simultaneously, one element at a time. Instead of writing messy index-based loops, zip() gives you a clean, readable way to work with related data that lives in separate sequences. In one line: zip(iter1, iter2) pairs up elements by position and … Read more >>

How to Unpack Tuples in Python

python unpack tuple

Unpacking a tuple in Python means extracting its values and assigning them to individual variables in a single, clean statement. Instead of accessing elements one by one using index notation like data[0], data[1], unpacking lets you do it all at once, making your code shorter, more readable, and more Pythonic. In one line: a, b, c = (1, … Read more >>

How to Sort Tuples by the Second Element in Python

Sort by the Second Element in a Tuple in Python

In my years of developing Python applications, I have often come across situations where data isn’t structured exactly how I need it for a report or a dashboard. One of the most common tasks I perform is organizing data stored in tuples, specifically when I need to sort that data based on a specific value … Read more >>

How to Sort a Tuple in Python?

python sort tuple

In my decade of working with Python, I’ve often encountered developers who get tripped up by the immutability of tuples. Since you cannot modify a tuple once it is created, many beginners assume sorting them is a complex task. Actually, sorting a tuple is quite easy once you understand how Python handles data structures behind … Read more >>

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.