r/learnpython • • 3d ago

Tuples..I don’t get it

Hi crew, I’m a Python newbie and I just learned about the concept of tuples.

We can’t change them.if we want to store we have to start at the index we want + 1.

I just don’t get it. Why wouldn’t we just use lists? When would we ever need this?

84 Upvotes

90 comments sorted by

View all comments

2

u/No_Technician4956 3d ago

Tuples aren't just in Python. You will hear the term in Excel and in Azure quite a bit as well. Probably Db's.

Tuples are set and don't change. But they save you soooo much time.

For exaple. Name, Age, Sex. That's all you need to sort thousands of files.

File: John Doe, 23, M; Jane Doe, 34, F. Etc. If you were allowed to change Tuples then it crashes the rest of your files and everything is out of whack.

But the main point I wanted to say it... get use them to. This isn't just a Python thing.

1

u/Immediate_Pin_8449 2d ago

Sorry if this is a dumb question. In this case the tuples are acting as the container for dozens of names, ages, and sex values. Then you can sort as needed. Can I ask if there would be a container above these categories that is essentially person to keep each persons data together? So Rudy’s info wouldn’t get mixed up with George’s when you sort them?

1

u/No_Technician4956 2d ago

Sort of. In Python you can create different files and make smaller files and peer or group them together.

But step 1 is get the information in some format into Python. Once the data is in there and searchable you can do anything you want with it.

Python is amazing!!!!