r/learnpython • u/Delta_Warrior8 • Apr 20 '23
Guys what’s a tuple
I was working on a certification practice test and I ran into multiple questions about them. I’m in FLVS and apparently either I forgot most of my first semester, or they didn’t teach me enough.
also if you could tell me other things that Flvs might have not taught me that would be nice.
27
Apr 20 '23
Easily searchable:
1
2
1
u/Fishfortrout Apr 21 '23
Crazy with ChatGPT everywhere and people still come ask simple questions on one of the slowest methods of getting an answer. Lol
-1
u/AtomicHyperion Apr 20 '23
Also easily answerable in a comment.
7
Apr 20 '23
/r/learnpython used to have a posting rule about "no easily googleable questions". It's far better to point the OP at some tutorial that will explain it in more detail than I can manage on mobile.
Some people just got to moan, I guess.
2
u/AtomicHyperion Apr 20 '23
How is this a concept that is hard to explain on mobile?
A list is a list of objects that is mutable
A tuple is a list of object that is immutable
mutable means can be changed after creation, immutable means cannot be changed after creation.
How is the concept hard to type on mobile? I literally typed this comment on my phone.
8
Apr 20 '23
And you haven't explained the details, like what "immutable" and "mutable" mean. Or why we use tuples instead of lists beyond them being immutable.
I would rather point the user at a more considered and more detailed write-up on the 'net. You prefer to write incomplete answers and whine about other people not doing what you think is best. Enjoy.
1
u/AtomicHyperion Apr 20 '23
And you haven't explained the details, like what "immutable" and "mutable" mean
Actually I did, third sentence.
Or why we use tuples instead of lists beyond them being immutable.
That is fair. But OP didn't really ask why they were used, just what they were.
You prefer to write incomplete answers
My answer isn't incomplete. It completely answers OP's question. And OP is capable of googling anyway.
and whine about other people not doing what you think is best.
So contradicting you is whining?
2
u/tanoshi-ka Apr 20 '23
as interesting as it was to read thru your convo, just a simple question.
did your answer contain the amount of info as it has in the webpage mentioned? or, better yet, which ans will leave the OP with a better understanding of the concept?
0
Apr 20 '23
NO bEing a prOgrammer means you HAVE to know how to GOOGLE!!!!
2
u/Alwaysragestillplay Apr 21 '23
It actually does though. Asking directly on forums should be a last resort because of the time inefficiency.
10
u/Technical_Flamingo54 Apr 20 '23
It's an unmutable and ordered, and hence hashable, iterable.
1
u/Delta_Warrior8 Apr 20 '23
hashable?
12
u/Technical_Flamingo54 Apr 20 '23
A hash is the computational equivalent of a mnemonic. The result is that it's more computationally efficient than other ordered iteranles, like lists.
6
Apr 20 '23 edited Apr 20 '23
It comes from discrete mathematics. I wrote a detailed explanation about it.
TLDR:
A
tupleis a finite, ordered sequence of objects.It differs from a
setbecause it can allow multiple of the same object.It differs from a
listbecause it is immutable (cannot be changed).Because it is immutable, it is hashable (unique).
11
u/elbiot Apr 20 '23
Though technically "just a list you can't change" it plays a different role because of this.
A list will contain a bunch of the same type of thing usually. Because a tuple is immutable, the positions usually have meaning. That is, the first position will tend to be one type of thing and the second another and so on. people use named tuples for that reason.
4
2
1
u/AtomicHyperion Apr 20 '23
A tuple is like a list, but it is immutable meaning it can't be changed once created. A list can be changed after it is created.
1
u/tanoshi-ka Apr 20 '23
ah among everything, when you use a return statement like return a, b its actually returning a and b as a tuple :))
0
u/TheRNGuy Apr 20 '23 edited Apr 20 '23
Use instead of list when you know you not gonna change it.
Or return from functions where you can do that:
foo, bar = myfunc(bas) // return tuple there instead of list.Though you could ofc still return list if you knew you gonna change it after returning from function, otherwise you'd have to convert tuple to a list.
18
u/[deleted] Apr 20 '23
What is a FLV?