+ 1

How put a element in a particular index of a list

List = ['y', 'i', 't'] If i want List [2] = u?

18th Feb 2022, 5:56 PM
Nisha
5 Answers
+ 3
List.insert(1, 'u')
18th Feb 2022, 6:30 PM
Мартин 😑🎵
Мартин 😑🎵 - avatar
+ 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)
18th Feb 2022, 6:26 PM
Jayakrishna 🇮🇳
+ 1
If b= 'u' Can i replace like l[2] = b ?
18th Feb 2022, 8:53 PM
Nisha
+ 1
Of course lists are mutable but tuples aren't so you can
18th Feb 2022, 8:54 PM
Мартин 😑🎵
Мартин 😑🎵 - avatar
+ 1
Experiment in playground. If something goes wrong, you can ask here... if b == 'u' : l[2] = b
18th Feb 2022, 9:04 PM
Jayakrishna 🇮🇳