3

I would like to create an empty set in Python.

I tried set1 = set() as mentioned here.

However I get the error:

set1 = set()
TypeError: 'dict' object is not callable

How can I create an empty set in Python?

Asmita Poddar
  • 524
  • 1
  • 11
  • 27

2 Answers2

2

Unfortunately foo = set() is the right way to declare empty set in both python 2 and python 3.

I guess you have a set = {} in the former lines.

You can try print(type(set)) to check it.

Fu Hanxi
  • 186
  • 1
  • 15
0

I get the same error while not having any already declared foo before declaring with foo = set().

From this answer, it works for me using an emty tuple, like so :

foo = {*()}
WQT
  • 1
  • 1