+ 2

Python - Why is output "None"?

lst = [].append(5) print (lst)

24th Mar 2020, 7:09 AM
Paolo De Nictolis
Paolo De Nictolis - avatar
4 Answers
+ 6
lst=[] lst.append(5) print (lst) Check this lesson about lists functions: https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2433/
24th Mar 2020, 7:17 AM
Jesus Eduardo CanulK
Jesus Eduardo CanulK - avatar
+ 3
If u wanna append any element in a list u should write this lst=[] lst.append(5) print(lst) Out put is [5]
24th Mar 2020, 7:19 AM
Muhammad Galhoum
Muhammad Galhoum - avatar
+ 1
Append will only modify the original list. So the original list in your example is [].. lst will receive the Return value of append method, which is "None". To get correct result, use jesus' solution...
24th Mar 2020, 7:21 AM
G B
G B - avatar