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

1 Answer

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

 



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

Related questions

...