Dee
0
Q:

how to append to tuple in python

some_tuple = ('dog', 'cat')
some_data = 'cow' # some data we want append to tuple

some_tuple += (some_data,)
1
apple = ('fruit', 'apple')
banana = ('fruit', 'banana')
dog = ('animal', 'dog')
# Make a list with these tuples
some_list = [apple, banana, dog]
# Check if it's actually a tuple list
print(some_list)
# Make a tuple to add to list
new_thing = ('animal', 'cat')
# Append it to the list
some_list.append(new_thing)
# Print it out to see if it worked
print(some_list)
1
a = ('2',)
b = 'z'
new = a + (b,)
1

New to Communities?

Join the community