[Tutor] Do _all_ Python builtin methods/functions return "None" IF ...

Alan Gauld alan.gauld at yahoo.co.uk
Sat Jan 27 04:18:38 EST 2018


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.

So if you come from SmallTalk, Python is horribly inconsistent.
If you come from C then its wonderfully consistent :-)

As with all languages you just get used to the foibles.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list