TIL: Sets, the add() method and None

Hi all, I am new to the field of Data and taking tiny steps every day to learn something.

I love the expression - TIL or Today I Learned as a way to expand learning beyond myself and also to learn from another in tiny bits.

So, TIL this quirk while learning about sets and the add() method -

The add() method adds elements, provided it is a unique one, to a set.
But if we run the commands:

    set_names = {'Megan', 'Rahul', 'Bodhi'}

    print(set_names.add('Seema')) 

The output is: any guesses?

    None

That’s because the .add() method does not itself return a value and that is reflected when a None object is returned, which by definition implies something with no value.

4 Likes