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.)

Answer from Maltysen 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 - Brief description on when to use parentheses `()`, square brackets `[]` and curly braces `{}` in python
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.

Discussions

Brackets where to use
https://www.pythoncheatsheet.org/cheatsheet/basics More on reddit.com
🌐 r/learnpython
14
5
May 26, 2024
Meaning of square brackets
HI I wonder if any one can help me understanding the use of the square brackets on the end of this statement. mail_ids = mails[0].decode().split()[-2:] How does the [-2:] work? thanks dazza000 More on discuss.python.org
🌐 discuss.python.org
0
0
October 24, 2022
Add curly brackets to python please
**Please add curly brackets to the python language just like Java. If not that at least have editors like python highlight the indeting of classes and methods and put class or method label within the highlighting so the developer knows where they are. ** More on discuss.python.org
🌐 discuss.python.org
0
4
July 14, 2024
Math brackets in python? - Stack Overflow
Now I'm talking about MATH brackets, not python brackets, I know that parentheses () work like in maths, ex: i = 5*(2+2) print (i) #output = 20 But square brackets [] and curly brackets {} don't w... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GeeksforGeeks
geeksforgeeks.org › python › parentheses-square-brackets-and-curly-braces-in-python
Parentheses, Square Brackets and Curly Braces in Python - GeeksforGeeks
July 26, 2025 - Curly braces define dictionaries and sets, both of which are mutable collections. Square brackets are crucial for defining lists and accessing elements through indexing and slicing. Mastery of these symbols allows Python developers to effectively manipulate data structures and perform various operations, enhancing their coding proficiency.
🌐
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(). ...
🌐
PyPI
pypi.org › project › brackets
brackets · PyPI
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Plain English
python.plainenglish.io › pythons-brackets-parentheses-and-curly-braces-60cdc236cdd6
Python’s Brackets, Parentheses, and Curly Braces | by Emmanuel Adebanjo | Python in Plain English
August 22, 2023 - Brackets — [], parentheses — (), & curly braces — {} are fundamental concepts that should be understood when dealing with the Python…
Find elsewhere
🌐
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.
🌐
Processing
py.processing.org › reference › indexbrackets
[] (Index brackets) \ Language (API)
Python Mode for Processing extends the Processing Development Environment with the Python programming language.
🌐
Python.org
discuss.python.org › python help
Meaning of square brackets - Python Help - Discussions on Python.org
October 24, 2022 - HI I wonder if any one can help me understanding the use of the square brackets on the end of this statement. mail_ids = mails[0].decode().split()[-2:] How does the [-2:] work? thanks dazza000
🌐
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.
🌐
Python.org
discuss.python.org › python help
Add curly brackets to python please - Python Help - Discussions on Python.org
July 14, 2024 - **Please add curly brackets to the python language just like Java. If not that at least have editors like python highlight the indeting of classes and methods and put class or method label within the highlighting so the developer knows where they are. **
🌐
Edlitera
edlitera.com › blog › posts › python-parentheses
Python Parentheses Cheat Sheet | Edlitera
In this article, I've demonstrated some of the different uses for standard parentheses, square brackets, and curly braces in Python that you can use as a cheat sheet.
🌐
Quora
quora.com › What-are-the-different-meanings-of-brackets-in-Python-programming
What are the different meanings of brackets in Python programming? - Quora
Answer (1 of 4): What are the different meanings of brackets in Python programming? Round Brackets: * used to represent tuples like (1, 2, 4). * used to group expressions like in (a + b) * c + (x**p)**q - (f - g) #without brackets the expression will have different semantic. * used to enclo...
🌐
Hacker News
news.ycombinator.com › item
Bython: Python with braces. Because Python is awesome, but whitespace is awful | Hacker News
March 16, 2024 - I just wrote my code as normal (indented, thank you very much) and could ignore semicolons and curly braces, and the code just ran · I was done in half the time
🌐
Quora
quora.com › What-is-the-difference-between-and-brackets-in-Python
What is the difference between {} and [] brackets in Python? - Quora
... Software Engineer at TBO.com ... facing each other ([ ]), which is legal Python, and means “empty list” (a list with no elements, not even None)....
🌐
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.
A set of tools for Python 3 featuring smart autocompletion, quickdocs, goto definition, linting and more. - bazitur/brackets-python-tools
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%
🌐
AskPython
askpython.com › home › how to print brackets in python?
How to Print Brackets in Python? - AskPython
May 30, 2023 - That means they are used to specify something. In Python, we use indentation instead of curly braces, but curly braces are still used just not for indentation. They are used for denoting a set or a dictionary.
🌐
GitHub
github.com › mathialo › bython
GitHub - mathialo/bython: Python with braces. Because python is awesome, but whitespace is awful. · GitHub
Bython is a Python preprosessor which translates curly brackets into indentation.
Starred by 2.6K users
Forked by 102 users
Languages   Python 88.1% | Roff 9.3% | Makefile 2.5% | Shell 0.1%