Asmita Poddar
Asmita Poddar

Reputation: 532

Create Empty Set in Python: TypeError: 'dict' object is not callable

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?

Upvotes: 3

Views: 1608

Answers (2)

WQT
WQT

Reputation: 11

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 = {*()}

Upvotes: 1

Fu Hanxi
Fu Hanxi

Reputation: 196

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.

Upvotes: 2

Related Questions