+ 1

Error in list function

Whats wrong with this code? words=("hey","you") words.insert(1, "yes") The idle brings an error message

8th Apr 2020, 1:46 PM
Brian Muchai
Brian Muchai - avatar
2 Answers
+ 6
look, here 'words' is a tuple. Tuple types are iterable but they cannot be changed. They are immutable type objects. Do like below instead. words =["hey", "you"] words.insert(1, "yes") new = tuple(words) print(new)
8th Apr 2020, 1:53 PM
M Tamim
M Tamim - avatar
0
Ooh, its a list, thanks
8th Apr 2020, 1:58 PM
Brian Muchai
Brian Muchai - avatar