[Tutor] How is "set(ls).add('a') evaluated? [Was: Re: A program that can check if all elements of the list are mutually disjoint]

Cameron Simpson cs at cskk.id.au
Sun Jun 6 19:05:56 EDT 2021


On 05Jun2021 21:32, boB Stepp <robertvstepp at gmail.com> wrote:
>On Sat, Jun 5, 2021 at 9:19 PM boB Stepp <robertvstepp at gmail.com> 
>wrote:
>> > Why are these different in their results?  # Referring to 
>> > difference in return values for set add() and union() methods.

"add" is a verb. It modifies the set. "union" is a noun: it returns a 
thing computed from the set(s).

>I find it really hard to remember which functions and methods return
>"None" and operate by side effect with those that return a new object.

Grammar helps, provided that people have put a little effort into naming 
the API calls.

Also, consider what is sensible for the operation. .add() builds on an 
existing set. .union() returns a computation of sets.

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Tutor mailing list