0

Python - Why is the output None when the extend() method is placed inside print()?

x = [1,2,3] x.extend([4,5,6]) print(x) # outputs [1, 2, 3, 4, 5, 6] x = [1,2,3] print(x.extend([4,5,6])) # outputs None --> Why does this NOT output [1, 2, 3, 4, 5, 6]?

13th Oct 2020, 9:29 PM
Solus
Solus - avatar
2 Respostas
+ 5
extend is a method that doesn't return anything. It operates "in place" so it changes the list.
13th Oct 2020, 9:32 PM
Russ
Russ - avatar
+ 3
The function <list>.extend() doesn't return a value. The function just extends the list.
13th Oct 2020, 9:34 PM
Alex
Alex - avatar