You need to make the second element a 1-tuple, eg:
a = ('2',)
b = 'z'
new = a + (b,)
Answer from Jon Clements on Stack OverflowHow do you add item to a tuple list you are looping over? I know with lists you use an iterator but it doesn't seem to work with tuple?
tuples are immutable. for i, x in enumerate(combos[:]): print(x) print(x[0]) print(x[1]) combos.remove(combos[i]) tuple_to_be_added = (" x += (x[0].similarity(x[1]),) ", " doesn't mean anything ") combos.insert(i,tuple_to_be_added) print(combos[i]) this should work. More on reddit.com
python - Efficient way to add elements to a tuple - Stack Overflow
I want to add elements to a tuple. I found 2 ways to do it. This and this answers say add two tuples. It will create a new tuple a = (1,2,3) b = a + (5,) Where as this says, convert the tuple to l... More on stackoverflow.com
Adding elements to an empty tuple-python
In my opinion, it never worked. The tuple really is immutable. Its content can sometimes be changed (then the tuple object is still immutable but not hashable), but the number of elements can never change. You should never be able to add elements to an empty tuple. More on experts-exchange.com
Ways to unpack a tuple with 1 element
There's also [hist] = conn.query(hist_query).fetchone() More on reddit.com
Videos
00:56
Add Element to Python Tuple! - YouTube
05:20
Write a Python Program to Add an Item in a Tuple - YouTube
How to Add an item in a tuple in Python
14:32
Python's tuple Data Type: Creating a Tuple & Retrieving Elements ...
01:41
Add and Update Values from a Tuple in Python (Convert into List) ...
W3Schools
w3schools.com โบ python โบ python_tuples_update.asp
Python - Update Tuples
Create a new tuple with the value "orange", and add that tuple: thistuple = ("apple", "banana", "cherry") y = ("orange",) thistuple += y print(thistuple) Try it Yourself ยป ยท Note: When creating a tuple with only one item, remember to include a comma after the item, otherwise it will not be identified as a tuple.
Reddit
reddit.com โบ r/learnpython โบ how do you add item to a tuple list you are looping over? i know with lists you use an iterator but it doesn't seem to work with tuple?
r/learnpython on Reddit: How do you add item to a tuple list you are looping over? I know with lists you use an iterator but it doesn't seem to work with tuple?
May 22, 2022 -
combos = [(Walking down the road on the pavement., Working with computers and programming can be engaging.), (Walking down the road on the pavement., Let us discuss programming in detail.), (Working with computers and programming can be engaging., Let us discuss programming in detail.)] for x in combos: print(x) print(x[0]) print(x[1]) x += (x[0].similarity(x[1]),) print(x) print(combos)
Nothing has then changed in the combos tuple. So I try iterator like I would with lists:
combos = [x += (x[0].similarity(x[1]),) for x in combos]
^^
SyntaxError: invalid syntaxCan I still use list iterator but my syntax was just wrong somehow?
How to deal with these things? Tuples seem more of a nuisance to deal with than other objects but the return list from collections brings a tuple so thought I might as well continue to work with it rather than convert to something else if it is a simple fix.
I want to loop over the existing tuple objects, doing the similarity check on each and appending the result of the check to the current tuple item.
EDIT: Clarifying what I want to do.
EDIT2: More clarifying.
Top answer 1 of 4
2
tuples are immutable. for i, x in enumerate(combos[:]): print(x) print(x[0]) print(x[1]) combos.remove(combos[i]) tuple_to_be_added = (" x += (x[0].similarity(x[1]),) ", " doesn't mean anything ") combos.insert(i,tuple_to_be_added) print(combos[i]) this should work.
2 of 4
2
You canโt add to a tuple; theyโre an immutable collection.
Devcamp
bottega.devcamp.com โบ full-stack-development-javascript-python โบ guide โบ how-to-add-elements-tuple-leveraging-re-assignment
How to Add Elements to a Tuple by Leveraging Re-Assignment
So we can't simply rely on hard coding our elements. Instead what we're going to have to do is we're going to dynamically alter this on the fly and leverage reassignment in order to do it. So I'm going to come here and let's walk through reassignment so I'm gonna say post and say post = post which is our current tuple plus and now we're going to add our new tuple element.
Codefinity
codefinity.com โบ courses โบ v2 โบ 102a5c09-d0fd-4d74-b116-a7f25cb8d9fe โบ 70acdec0-68a1-4d5a-9847-f81d1a8569d0 โบ bf280dbf-e2e1-44dd-8eff-abc79acbb024
Learn Adding Items to a Tuple: Alternative Approaches Using Lists | Mastering Python Tuples
This is something we explored a few chapters back. If you want to add one or more elements, simply create a new tuple with these elements and combine it with the original tuple.
TutorialsPoint
tutorialspoint.com โบ How-to-append-elements-in-Python-tuple
How to append elements in Python tuple?
August 22, 2023 - In this example, we are updating a tuple by slicing it into two parts and inserting new elements between the slices โ ยท # Original tuple T1 = (37, 14, 95, 40) # Elements to be added new_elements = ('green', 'blue', 'red', 'pink') # Extracting slices of the original tuple # Elements before index 2 part1 = T1[:2] # Elements from index 2 onward part2 = T1[2:] # Create a new tuple updated_tuple = part1 + new_elements + part2 # Printing the updated tuple print("Original Tuple:", T1) print("Updated Tuple:", updated_tuple)
PyTutorial
pytutorial.com โบ how-to-add-to-a-tuple-in-python
PyTutorial | How to Add to a Tuple in Python
January 27, 2026 - Then you can add new elements at the start, middle, or end. This is a very Pythonic approach. base_tuple = (10, 20, 30) print("Base Tuple:", base_tuple) # Add to the end tuple_end = (*base_tuple, 40, 50) print("Added to End:", tuple_end) # Add to the beginning tuple_start = (0, 5, *base_tuple) print("Added to Start:", tuple_start) # Add in the middle (more complex) tuple_middle = (*base_tuple[:2], 25, *base_tuple[2:]) print("Added in Middle:", tuple_middle)
Tutorial Reference
tutorialreference.com โบ python โบ examples โบ faq โบ python-how-to-insert-an-elment-into-a-tuple
How to Add Elements to Tuples in Python | Tutorial Reference
The most direct and Pythonic way to "append" to a tuple is to create a new tuple by concatenating the original tuple with a new tuple containing the element(s) you want to add.
CodeRivers
coderivers.org โบ blog โบ python-add-tuple
Python Add Tuple: A Comprehensive Guide - CodeRivers
February 22, 2026 - This method can be useful when you want to insert elements at specific positions. tuple3 = (1, 2, 3) new_element = 4 new_tuple2 = (*tuple3, new_element) print(new_tuple2) Here, we unpack the elements of tuple3 using the * operator and then add the new_element at the end to create a new tuple new_tuple2.
Experts Exchange
experts-exchange.com โบ questions โบ 29277836 โบ Adding-elements-to-an-empty-tuple-python.html
Solved: Adding elements to an empty tuple-python | Experts Exchange
October 10, 2024 - t = (1, 2, 3, 4, 5.6) print(t, type(t), id(t)) t = tuple( i**2 if i%2 == 0 else i**3 for i in t ) print(t, type(t), id(t)) ... EARN REWARDS FOR ASKING, ANSWERING, AND MORE. Earn free swag for participating on the platform. ... Python is a widely used general-purpose, high-level programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in other languages.
DataCamp
datacamp.com โบ tutorial โบ python-tuples-tutorial
Python Tuples Tutorial: Create & Use Tuples Functions with Examples | DataCamp
February 7, 2018 - However, this is often a debatable ... article for the same. For now, lets just say tuples are immutable in general. You can't add elements to a tuple because of their immutable property....
TutorialsPoint
tutorialspoint.com โบ python-program-to-add-elements-to-a-tuple
Python Program to add elements to a Tuple
February 17, 2023 - We know that we can use the list method to convert the tuples to lists and then we can make use of append method of list to add however many items we like, when we will be done with adding elements, we then convert the list to tuple using type conversion. This is a roundabout way of adding elements, but it saves us the effort to check for type mismatch between + operators.