0
When to use tuples in python, what even are they?
What's a tuple? When should it be used in python? I'm trying to figure out errbot, a chat box program written in python, and it states that sometimes a "tuple" is required and it refers to putting a trailing "," after a list when inside parenthesis. Like so: thing = ("things thing one","things thing two",) I do not know what it is or why, pls help :)
6 Answers
+ 3
Tuples are just unchangeable lists, you use it when you want a data structure that can't be changed :) for example maybe you want to have birth records, you don't want to change something like that.
+ 3
⊹≒tɧε8шσσɖɕนttεг≓⊹ also, when defining a tuple with one element, it's mandatory to add a trailing comma so python knows it's not just redundant parentheses :)
+ 2
Tuples are similar to lists, but they are immutable. See Python Data Structures 16.1 and 17.1.
+ 2
"In some code samples you might see a comma after the last item in the list. It's not mandatory, but perfectly valid." in python core 23.1 it sez this aha!
+ 1
Calvin [Inactive] ooooooh so then if you instantiate a variable with say var = (), you should use the tuple thing afterwards? (Tuple i mean comma). Thats like a "hey im not reduntant!" stop from when it was started that way.
+ 1
Or its to assert that the () ARE redundant when passed through? Giving the data without parenthesis