Empty set literal?


[] = empty list

() = empty tuple

{} = empty dict

Is there a similar notation for an empty set? Or do I have to write set()?

Answer rating: 603

No, there"s no literal syntax for the empty set. You have to write set().

Answer rating: 73

By all means, please use set() to create an empty set.

But, if you want to impress people, tell them that you can create an empty set using literals and * with Python >= 3.5 (see PEP 448) by doing:

>>> s = {*()}  # or {*{}} or {*[]}
>>> print(s)

this is basically a more condensed way of doing {_ for _ in ()}, but, don"t do this.

Get Solution for free from DataCamp guru