Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python : How and why is this syntax working ? {1,2,3,4}

As we know,

{} # Represents a dict

And

{'one': 1} # Again a dict

How and why is this a set :

{'one', 'two', 'three', 'four'} # I thought it should give syntax error

But it gives :

set(['one', 'two', 'three', 'four']) # Strange ?? [ Should this happen ? ]

Can you provide a link to some official doc discussing the same ?

like image 629
Yugal Jindle Avatar asked Dec 21 '22 15:12

Yugal Jindle


1 Answers

Set literals are a 3.x feature that has been backported into 2.7.

This is a useful feature - note that set comprehensions are also allowed.

like image 125
Gareth Latty Avatar answered Jan 06 '23 23:01

Gareth Latty