+ 1

How do i implement a function that takes in 3 parameters' tuple index and a value and change the value at the index to a new val

8th Mar 2020, 5:15 AM
Tan
2 ответов
+ 2
My version would have been this: def change_tup(tup, idx, val): return tup[:idx]+(val,)+tup[idx+1:]
8th Mar 2020, 7:52 AM
HonFu
HonFu - avatar
+ 2
Yeah, when you use just parentheses for a single value, Python will just dissolve them, like in (1+2)*3.
8th Mar 2020, 7:58 AM
HonFu
HonFu - avatar