0
Why is this wrong
#this doesn't work, why not? list = [a,b,c,d] list = list.append(e) print(list) #instead this works, why? list = [a,b,c,d] list.append(e) print(list)
3 Réponses
+ 6
list.append returns None. The method modifies the list inplace.
https://docs.python.org/3/tutorial/datastructures.html
+ 2
1. None of them should work, a is a variable, and "a" is a string, maybe you meant "a", "b"... ?
2. The first one is the correct one, what problems did you have when running the code?
+ 1
On the line list = list.append(e) you are trying to create a string containing the value of list.append(e) whereas list.append is the correct syntax for adding a value to a list.