Answers for "how ot create a tuple and add elements to it in python"

2

appending items to a tuple python

tuple_item = ("Grepper")
#print(tuple_item)
converted = list(tuple_item)
#print(type(converted))
converted.append(" is amazing")
convert_to_tur = tuple(converted)
print(convert_to_tur)
Posted by: Guest on July-26-2021
0

add item to tuple

tpl1 = ('BMW', 'Lamborghini', 'Bugatti')
print(tpl1)
#Now you have to add an item
tpl1 = list(tpl1)
print(tpl1)
tpl1.append('Mercedes Benz')
tpl1 = tuple(tpl1)
print(tpl1)
#*Run the code*
>>  ('BMW', 'Lamborghini', 'Bugatti')
>>  ['BMW', 'Lamborghini', 'Bugatti']
>>  ('BMW', 'Lamborghini', 'Bugatti', 'Mercedes Benz')
#Task accomplished
Posted by: Guest on July-31-2021

Code answers related to "how ot create a tuple and add elements to it in python"

Python Answers by Framework

Browse Popular Code Answers by Language