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)

14th Feb 2020, 9:57 AM
Kanyanta Makasa
Kanyanta Makasa - avatar
3 ответов
+ 6
list.append returns None. The method modifies the list inplace. https://docs.python.org/3/tutorial/datastructures.html
14th Feb 2020, 10:21 AM
Hatsy Rei
Hatsy Rei - avatar
+ 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?
14th Feb 2020, 10:07 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 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.
14th Feb 2020, 11:38 AM
Matthew Anderson