What am I doing wrong here?
a = set().add(1)
print a # Prints `None`
I'm trying to add the number 1
to the empty set.
What am I doing wrong here?
a = set().add(1)
print a # Prints `None`
I'm trying to add the number 1
to the empty set.
The add method updates the set, but returns None.
You should do this:
Notice that you're assigning to
a
the result of adding1
, and theadd
operation, as defined in Python, returnsNone
- and that's what is getting assigned toa
in your code.Alternatively, you can do this for initializing a set: