Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

change value in tuple

# i want to change index 2 to a value of 200
t = (1, 2, 3, 4, 5) # a random tuple
# if we just do t[2] = 200, it will result in an error as tuples are immutable

t = list(t)
t[2] = 200
t = tuple(t)

# this changes our tuple to a list, changes the value, 
# and converts it back to a list
 
PREVIOUS NEXT
Tagged: #change #tuple
ADD COMMENT
Topic
Name
9+6 =