-1

Python Theoretical Question I'd like to learn theory behind why "print(i.extend(j))" DOESN'T work. It's OUTPUT is: "None". print(j) DOES work (It's OUTPUT is: "[4, 5, 6, 7, 8, 9]")

i = [1, 2, 3]
j = [4, 5, 6]
k = [7, 8, 9]
# I'd like to learn theory as to why following doesn't work
# OUTPUT is: "None"  
print(i.extend(j))
# Following does work (OUTPUT is:  "[1, 2, 3, 4, 5]")
j.extend(k)
print(j)
vaultah
  • 44,105
  • 12
  • 114
  • 143
  • Thank you for answer valutah and Tony. I'm new to Python and stackoverflow. I looked on stackoverflow for a while and couldn't find anything about the list.extend method. Could someone tell me how to find info about the list.extend method using search on the python.org site? I've spent 30 minutes and can't do it. Thank you, Mike – mtnmanmike Sep 18 '16 at 15:21
  • I agree, sometimes it's hard to search the official documentation. The `extend` method is covered [here](https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types) and in the [tutorial](https://docs.python.org/3/tutorial/datastructures.html). You could also use the built-in `help` function: `help('list.extend')`. – vaultah Sep 18 '16 at 22:59

1 Answers1

-1

The answer is simple -

extend doesn't return anything, and any function that doesn't return a value is taken to have returned None.

Tony Suffolk 66
  • 9,358
  • 3
  • 30
  • 33