What's the difference between dict() and {}?

前端 未结 8 506
陌清茗
陌清茗 2020-12-12 13:53

So let\'s say I wanna make a dictionary. We\'ll call it d. But there are multiple ways to initialize a dictionary in Python! For example, I could do this:

8条回答
  •  不知归路
    2020-12-12 14:21

    In order to create an empty set we should use the keyword set before it i.e set() this creates an empty set where as in dicts only the flower brackets can create an empty dict

    Lets go with an example

    print isinstance({},dict) 
    True 
    print isinstance({},set) 
    False 
    print isinstance(set(),set) 
    True
    

提交回复
热议问题