Add Items

Once a tuple is created, you cannot add items to it. Tuples are unchangeable.

Example

You cannot add items to a tuple:

thistuple = ("apple", "banana", "cherry")

thistuple[3] = "orange" # This will raise an error

print(thistuple)

Create Tuple With One Item

To create a tuple with only one item, you have add a comma after the item, unless Python will not recognize the variable as a tuple.

Example

One item tuple, remember the commma:

thistuple = ("apple",)

print(type(thistuple))


#NOT a tuple

thistuple = ("apple")

print(type(thistuple))

Remove Items

Note: You cannot remove items in a tuple.

 Tuples are unchangeable, so you cannot remove items from it, but you can delete the tuple completely:

Example

The del keyword can delete the tuple completely:

thistuple = ("apple", "banana", "cherry")

del thistuple

print(thistuple) #this will raise an error because the tuple no longer exists

Join Two Tuples

To join two or more tuples you can use the + operator:

Example

Join two tuples:

tuple1 = ("a", "b" , "c")

tuple2 = (1, 2, 3)


tuple3 = tuple1 + tuple2

print(tuple3)

Jay Kakadiya

Jay Kakadiya Creator

I am a computer field, & i am Web developer.

Suggested Creators

Jay Kakadiya