Python: How and why does this syntax work? {1,2,3,4}

As known,

{} # Represents a dict 

and

 {'one': 1} # Again a dict 

How and why is this set:

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

But he gives:

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

Can you provide a link to some white paper discussing the same thing?

+4
source share
1 answer

A set of literals is a 3.x function that was inverted in 2.7.

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

+11
source

Source: https://habr.com/ru/post/1438375/


All Articles