This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: print statement not showing valid result
Type: behavior Stage:
Components: Windows Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: laki, loewis
Priority: normal Keywords:

Created on 2012-08-10 08:20 by laki, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg167859 - (view) Author: (laki) Date: 2012-08-10 08:20
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32
>>> a = [1,2]
>>> b = [2,3]
>>> a.extend(b)
>>> a
[1, 2, 2, 3]
>>> print [1,2].extend([2,3])
None

I did not test this in linux.
msg167861 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2012-08-10 08:58
This is not a bug. extend is a procedure with a side effect: the "self" object (i.e. "a" in your example) is modified.

By convention, procedures return None in Python, as opposed to functions, which have no side effect but return a result. This is to avoid code like

def combine(a, b):
  return a.extend(b)

a = ...
b = ...
c = combine(a,b)

If extend would return the "self" list, then people may think that they get a fresh, new list, and then wonder why a is modified.

IOW: your bug report is actually invalid; the result that print shows is exactly the right result that extend returns.
History
Date User Action Args
2022-04-11 14:57:34adminsetgithub: 59819
2012-08-10 08:58:13loewissetstatus: open -> closed

nosy: + loewis
messages: + msg167861

resolution: not a bug
2012-08-10 08:20:16lakicreate