How to replace an element at specific index in tuple with Python

1 Answer

0 votes
tpl = (87, 234, 4, 9813, 99)
  
idx = 3
tpl = tpl[ : idx] + (100 ,) + tpl[idx + 1 : ]
  
print(tpl)
  
  
  
'''
run:
  
(87, 234, 4, 100, 99)
  
'''

 



answered Jan 29, 2020 by avibootz
edited Jan 29, 2020 by avibootz

Related questions

1 answer 185 views
1 answer 180 views
2 answers 188 views
1 answer 176 views
1 answer 172 views
2 answers 294 views
...