There are two issues with the set literal syntax:

my_set = {'foo', 'bar', 'baz'}
  1. It's not available before Python 2.7

  2. There's no way to express an empty set using that syntax (using {} creates an empty dict)

The section of the docs outlining this syntax is here.

Answer from bgporter on Stack Overflow
๐ŸŒ
Data Science Discovery
discovery.cs.illinois.edu โ€บ guides โ€บ Python-Fundamentals โ€บ brackets
Parentheses, Square Brackets and Curly Braces in Python - Data Science Discovery
March 22, 2024 - Generally, parentheses () are used for grouping expressions, defining functions or passing arguments, and defining tuples. Square brackets [] are used for creating lists, indexing elements and slicing snippets. Curly braces {} serve two main ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_sets.asp
Python Sets
thisset = set(("apple", "banana", "cherry")) # note the double round-brackets print(thisset) Try it Yourself ยป ยท There are four collection data types in the Python programming language:
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ parentheses-square-brackets-and-curly-braces-in-python
Parentheses, Square Brackets and Curly Braces in Python - GeeksforGeeks
July 26, 2025 - Note: To create empy sets in python use set(), my_set = {} will be an empty dictionary. Square brackets are used to define lists, indexing, and slicing.
๐ŸŒ
Processing
py.processing.org โ€บ reference โ€บ indexbrackets.html
[] (Index brackets) \ Language (API)
Python Mode for Processing extends the Processing Development Environment with the Python programming language.
Find elsewhere
๐ŸŒ
GitHub
github.com โ€บ bazitur โ€บ brackets-python-tools
GitHub - bazitur/brackets-python-tools: A set of tools for Python 3 featuring smart autocompletion, quickdocs, goto definition, linting and more.
You can customize interpreter either in Preferences File or in Python Tools Settings tab. Settings are accessible through standart brackets settings interface or 'File' menu ๐Ÿก’ Python Tools Settings.
Starred by 23 users
Forked by 7 users
Languages ย  JavaScript 46.5% | Python 45.6% | CSS 5.0% | HTML 2.9% | JavaScript 46.5% | Python 45.6% | CSS 5.0% | HTML 2.9%
๐ŸŒ
Reuven Lerner
lerner.co.il โ€บ home โ€บ blog โ€บ python โ€บ python parentheses primer
Python parentheses primer โ€” Reuven Lerner
November 10, 2022 - The square brackets tell Python that this is a list comprehension, producing a list. If you use curly braces, youโ€™ll get either a set or a dict back, and if you use regular parentheses, youโ€™ll get a generator expression (see above).
๐ŸŒ
James Madison University
w3.cs.jmu.edu โ€บ lam2mo โ€บ cs240_2014_08 โ€บ brackets.html
Setting up Brackets to use Python 3
July 23, 2025 - Launch the Brackets editor. I will assume you have already downloaded and installed it. Click the block icon on the right side of the editor window. Find the "Integrated Development" extension and install it. Open the "Edit" menu and choose "Edit Builder". Find the reference to "python" in the ...
๐ŸŒ
Real Python
realpython.com โ€บ python-sets
Sets in Python โ€“ Real Python
May 5, 2025 - You can define a new set by providing a comma-separated series of hashable objects within curly braces {} as shown below: ... The portion of this syntax enclosed in square brackets is ...
๐ŸŒ
Edlitera
edlitera.com โ€บ blog โ€บ posts โ€บ python-parentheses
Python Parentheses Cheat Sheet | Edlitera
Thatโ€™s why it's important to understand what each type of parentheses in Python represents and how to use each type of parentheses correctly in your Python code. In this article, I'll cover what standard parentheses, square brackets, and curly braces represent to Python when it interprets the code you've written.
๐ŸŒ
Pythontic
pythontic.com โ€บ containers โ€บ set โ€บ construction_using_braces
Python Set - Construction of python sets using curly braces | Pythontic.com
Construct mutable, non-frozen python set objects by specifying the elements separated by commas inside curly braces
๐ŸŒ
Codecademy
codecademy.com โ€บ learn โ€บ cspath-cs-101 โ€บ modules โ€บ cspath-python-lists โ€บ cheatsheet
CS101: Introduction to Programming: Python: Lists Cheatsheet | Codecademy
In Python, lists are ordered collections of items that allow for easy use of a set of data. List values are placed in between square brackets [ ], separated by commas. It is good practice to put a space between the comma and the next value.
๐ŸŒ
Quora
quora.com โ€บ In-Python-why-are-both-sets-and-dictionaries-able-to-be-defined-with-curly-braces
In Python, why are both sets and dictionaries able to be defined with {curly braces}? - Quora
Yes they both use {} (curly braces) as delimiters, but sets consist of single values, where as dictionaries have key value pairs separated by colons. Using a delimiter for two different things isnโ€™t difficult to a parser; Note that Python also uses normal brackets () for two different things (expressions, and function calls), and square brackets [] for list access and and dictionary access.
๐ŸŒ
Quora
quora.com โ€บ How-do-I-setup-Brackets-or-Atom-code-editor-to-run-Python-script
How to setup Brackets or Atom code editor to run Python script - Quora
Answer (1 of 5): In Visual studio code you can press[code ] ctrl + `[/code] that will open an in-app terminal in the below. If you opened project folder the terminal will be open on that location otherwise it will be open on default directory. You can run the script from there. You can also insta...
Top answer
1 of 4
82

Square brackets: []

Lists and indexing/lookup/slicing

  • Lists: [], [1, 2, 3], [i**2 for i in range(5)]
  • Indexing: 'abc'[0] โ†’ 'a'
  • Lookup: {0: 10}[0] โ†’ 10
  • Slicing: 'abc'[:2] โ†’ 'ab'

Parentheses: () (AKA "round brackets")

Tuples, order of operations, generator expressions, function calls and other syntax.

  • Tuples: (), (1, 2, 3)
    • Although tuples can be created without parentheses: t = 1, 2 โ†’ (1, 2)
  • Order of operations: (n-1)**2
  • Generator expressions: (i**2 for i in range(5))
  • Function or method calls: print(), int(), range(5), '1 2'.split(' ')
    • with a generator expression: sum(i**2 for i in range(5))

Curly braces: {}

Dictionaries and sets, as well as in string formatting

  • Dicts: {}, {0: 10}, {i: i**2 for i in range(5)}
  • Sets: {0}, {i**2 for i in range(5)}
    • Except the empty set: set()
  • In string formatting to indicate replacement fields:
    • F-strings: f'{foobar}'
    • Format strings: '{}'.format(foobar)

Regular expressions

All of these brackets are also used in regex. Basically, [] are used for character classes, () for grouping, and {} for repetition. For details, see The Regular Expressions FAQ.

Angle brackets: <>

Used when representing certain objects like functions, classes, and class instances if the class doesn't override __repr__(), for example:

>>> print
<built-in function print>
>>> zip
<class 'zip'>
>>> zip()
<zip object at 0x7f95df5a7340>

(Note that these aren't proper Unicode angle brackets, like โŸจโŸฉ, but repurposed less-than and greater-than signs.)

2 of 4
5

In addition to Maltysen's answer and for future readers: you can define the () and [] operators in a class, by defining the methods:

  • __call__(self[, args...]) for ()
  • __getitem__(self, key) for []

An example is numpy.mgrid[...]. In this way you can define it on your custom-made objects for any purpose you like.

๐ŸŒ
Open Book Project
openbookproject.net โ€บ books โ€บ bpp4awd โ€บ ch03.html
3. Strings, lists and tuples โ€” Beginning Python Programming for Aspiring Web Developers
In the case of lists or tuples, they are made up of elements, which are values of any Python datatype, including other lists and tuples. Lists are enclosed in square brackets ([ and ]) and tuples in parentheses (( and )).
๐ŸŒ
Afeld
python-public-policy.afeld.me โ€บ en โ€บ columbia โ€บ brackets.html
Brackets in Python and pandas โ€” Python for Public Policy @ Columbia University
In Python, parentheses are used in function definitions to specify the arguments. ... Then, parentheses are used to call functions, passing in the arguments (if any). ... When making a new instance of a class, you use parentheses after the class name. We saw this above with pd.DataFrame(). ...
๐ŸŒ
David Bieber
davidbieber.com โ€บ snippets โ€บ 2021-04-19-python-set-operations
Python set operations | David Bieber
Use parenthesis to create a tuple (1, 2, 3), square brackets to create a list [4, 5, 6], and squirrelly brackets to create a dict or set: {7: 8, 9: 10} makes a dict and {11, 12, 13} makes a set.