Skip to content

Commit 41272b9

Browse files
DOC: Clarify parentheses vs. brackets usage (GH#62314) updated
1 parent ada92d7 commit 41272b9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
.. _10min_tut_11_brackets_vs_parenthesis:
1+
In both Python and pandas, it’s important to understand the difference between parentheses ``()`` and square brackets ``[]``:
22

3-
Parentheses vs. Square Brackets in Python and pandas
4-
====================================================
3+
- **Parentheses** are used to call functions and methods. For example, ``df.mean()`` calculates the mean of a DataFrame, and parentheses are also used to group expressions, such as ``(a + b) * c``, or to create tuples: ``(1, 2, 3)``.
4+
- **Square brackets** are used for indexing, selecting data, and defining lists. In pandas, you use square brackets to select columns or filter data—for instance, ``df['A']`` selects column ``A``, while ``df[0:3]`` selects rows by position. In standard Python, square brackets are also used to define a list, as in ``my_list = [1, 2, 3]``.
55

6-
In Python and pandas, parentheses ``()`` and square brackets ``[]`` have distinct uses, which can sometimes be confusing for new users. Parentheses are used to call functions and methods (for example, ``df.mean()``), to group expressions in calculations (such as ``(a + b) * c``), and to create tuples. Square brackets, on the other hand, are used for defining lists and for indexing or selecting data—in both core Python and pandas. For example, ``df['A']`` selects column ``A`` from a DataFrame, and ``df[0:3]`` selects rows by position. In pandas, square brackets are always used when you want to select or filter data, while parentheses are used any time you are calling a method or function. Remember: use ``[]`` for selection or indexing, and ``()`` for function calls and grouping.
6+
Remember:
7+
**Use [] for selection or indexing, and () for calling functions or grouping expressions.**

0 commit comments

Comments
 (0)