+ 1
How put a element in a particular index of a list
List = ['y', 'i', 't'] If i want List [2] = u?
5 Respuestas
+ 3
List.insert(1, 'u')
+ 1
Are you tried that way.. ?
Try it once.. Result?
edit: ?
yes. it works list allows indexing and it is mutable or modifiable.
edit:
List = ['y', 'i', 't']
print(List)
List [2] = 'u'
print(List)
+ 1
If b= 'u'
Can i replace like
l[2] = b
?
+ 1
Of course
lists are mutable
but tuples aren't
so you can
+ 1
Experiment in playground. If something goes wrong, you can ask here...
if b == 'u' : l[2] = b