Tuples are immutable, you cannot append, delete, or edit them at all. If you want to turn a list into a tuple, you can just use the tuple function:
tuple(a)
If, for some reason, you feel the need to append to a tuple (You should never do this), you can always turn it back into a list, append, then turn it back into a tuple:
tuple(list(a)+b)
Keep getting votes for this, which means people keep seeing it, so time to update and remove misinformation.
It's OK to add elements to a tuple (sort of). That was a silly thing to say. Tuples are still immutable, you can't edit them, but you can make new ones that look like you appended by putting multiple tuples together. tuple(list(a)+b)
is stupid, don't do that. Just do tuple1 + tuple2
, because Python doesn't suck. For the provided code, you would want:
state = ()
for i in a:
state += (i,)
The Paul's response to this answer is way more right than this answer ever was.
Now I can stop feeling bad about this.