-1

I'm using extend function to add new item in a list. And gives me None in output.

 p=["a",1,"b",2,"c",3]
 a=p.extend(["d",4])
 print(a)

Output None

Why It is giving none instead of ['a', 1, 'b', 2, 'c', 3, 'd', 4]

Vishavjeet
  • 331
  • 7
  • 13
  • please check [ask] - you should at least specify what you wanted to do, what have you tried, what is going wrong and what is the desired output – Gsk Jun 14 '18 at 07:31

1 Answers1

1

Because using extend function, you just extend it but not make any new list. So nothing is assigned it variable a. You should do following:

p=["a",1,"b",3,"c",4]
p.extend(["qeq",14])
print(p)

This method does not return any value but add the content to existing list. Check this for more.

Innat
  • 16,113
  • 6
  • 53
  • 101