top of page

Immutable Tuples - like Bheeshma’s Unbreakable Vows

Python through the timeless wisdom of Indian Vedic mythology!
By drawing parallels between ancient stories and modern code, programming concepts become much more relatable, fun and easy to remember!

The Legendary Oath of Bhishma

Bhishma, originally named Devavrata, is revered as one of the most steadfast and noble characters in the Mahabharata. His story begins with a dilemma: King Shantanu, his father, wishes to marry Satyavati, but her father will only consent if Satyavati’s future children can inherit the throne. To resolve his father’s heartbreak and secure the kingdom’s future, Devavrata does the unimaginable—he renounces his claim to the throne and pledges lifelong celibacy, ensuring there would be no contest from his own descendants. This terrible oath, the “Bhishma Pratigya,” earns him the name Bhishma, meaning “the one with the incredible vow”.


Bhishma’s commitment is unwavering. Throughout his life, even when his own teacher Parashurama commands him to break his vow, Bhishma refuses, choosing his word above personal desire, duty, and even divine intervention. His vow shapes the destiny of the Kuru dynasty and is a profound lesson in honoring one’s promises—no matter the cost.


Tuples in Python: The Bhishma Parallel

In Python, a tuple is a collection that is ordered and, most importantly, immutable. Once a tuple is created, its values cannot be changed, mirroring the steadfastness of Bhishma’s oath. Just as Bhishma could not break his word after taking the vow, a tuple cannot be altered after creation.


Story to Code

Consider Bhishma’s decision:


bhishmas_vow = ("Renounce throne", "Lifelong celibacy", "Serve Hastinapur")

print(bhishmas_vow)
# ('Renounce throne', 'Lifelong celibacy', 'Serve Hastinapur')

Once assigned, any attempt to change an element of bhishmas_vow tuple, Python raises a TypeError indicating that tuples do not support item assignment. This illustrates how tuples are used to protect sacred or critical data from modification—in the same way Bhishma’s vow could not be changed by any force.


bhishmas_vow = ("Renounce throne", "Lifelong celibacy", "Serve Hastinapur")

# Attempt to change the second vow:
bhishmas_vow[1] = "Break celibacy"

OUTPUT->

Traceback (most recent call last):
  File "main.py", line 3, in <module>
    bhishmas_vow[1] = "Break celibacy"
TypeError: 'tuple' object does not support item assignment

Why This Matters

  • Tuples enforce data reliability and protection from unwanted change.

  • The TypeError message is a reminder for developers: if data must never change (like Bhishma’s vow), a tuple is the right choice.


Real World Tuples Applications

  • Storing coordinates in geometry or mapping

    • Points in 2D or 3D space (e.g., (x, y) for a location on a map) are naturally stored as tuples since their data is fixed and ordered.

  • Representing database records and heterogeneous data

    • A tuple can hold a record where each field is of a different type, such as (“Alice”, 30, “alice@example.com”), preserving immutable information.

  • Dictionary keys for compound identifiers

    • Since tuples are immutable and hashable, they are commonly used as keys in dictionaries: for example, dictionary[(user_id, date)] = transaction.

  • As fixed-size records for financial transactions

    • Payment processors and banking software store transaction details as tuples, e.g., (transaction_id, amount, currency, timestamp), since this data should not be changed after logging for audit/security reasons.

  • Storing immutable currency pairs or trading symbols

    • In forex and securities trading, tuples are used for immutable identifiers like (“USD”, “INR”) or (“NSE”, “RELIANCE”), ensuring trading algorithms don’t accidentally alter instrument IDs during processing.

Bhishma’s story teaches the power of commitment, and Python’s tuple celebrates that spirit in every line of immutable code. The next time a tuple is created, remember Bhishma—the guardian of the Kuru dynasty whose unbreakable vow shaped an epic, "Mahabharat", and inspired generations.
Pitahmaha -Devavratha; Gangaputra; Bheeshma
Pitahmaha -Devavratha; Gangaputra; Bheeshma

1 Comment


Put the topics you want to learn, or have a mythology story in your mind you want to connect the dots. Will try to get it for you!

Like
bottom of page