Does Python have an immutable list?

Yes. It’s called a tuple. So, instead of [1,2] which is a list and which can be mutated, (1,2) is a tuple and cannot. Further Information: A one-element tuple cannot be instantiated by writing (1), instead, you need to write (1,). This is because the interpreter has various other uses for parentheses. You can also do away with parentheses altogether: 1,2 is the same as (1,2) Note that a tuple is … Read more

Can I put a tuple into an array in python?

One thing to keep in mind is that a tuple is immutable. This means that once it’s created, you can’t modify it in-place. A list, on the other hand, is mutable — meaning you can add elements, remove elements, and change elements in-place. A list has extra overhead, so only use a list if you need to modify … Read more

TypeError: can only concatenate tuple (not “int”) in Python

Your checkAnswer() function returns a tuple: Here return right, answer returns a tuple of two values. Note that it’s the comma that makes that expression a tuple; parenthesis are optional in most contexts. You assign this return value to right: making right a tuple here. Then when you try to add 1 to it again, the error occurs. You don’t change answer within the function, so there … Read more

How does tuple comparison work in Python?

Tuples are compared position by position: the first item of the first tuple is compared to the first item of the second tuple; if they are not equal (i.e. the first is greater or smaller than the second) then that’s the result of the comparison, else the second item is considered, then the third and … Read more

Python AttributeError: ‘dict’ object has no attribute ‘append’

Like the error message suggests, dictionaries in Python do not provide an append operation. You can instead just assign new values to their respective keys in a dictionary. If you’re wanting to append values as they’re entered you could instead use a list. Your line user[‘areas’].append[temp] looks like it is attempting to access a dictionary at the … Read more