On 27Jan2018 09:18, Alan Gauld <alan.ga...@yahoo.co.uk> wrote:
On 27/01/18 02:56, boB Stepp wrote:
So my actual question is: For these types of methods/functions, is
Python Both versions 2 and 3) consistent throughout and *always*
returns None?
Mostly, but only for mutable objects.
So the string methods return a new string with the modifications
because the original string is immutable and cannot be changed.
So superficially, list handling methods return none on
modification but string methods return the modified string.
You need to bear in mind whether the object is mutable or
not to understand the expected result.
For a big more context, the general rule is: if the method fetches a value from
the object eg its length, of course it returns something other than None. But
if a method _modifies_ the object (append an element to a list, close a file),
just affecting its internal state, then the method will usually return None.
These modification methods _could_ return a value, but the general practice is
not to.
Cheers,
Cameron Simpson <c...@cskk.id.au> (formerly c...@zip.com.au)
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor