Open In App

Parentheses, Square Brackets and Curly Braces in Python

Last Updated : 26 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In Python, `()`, `{}`, and `[]` are used to represent different data structures and functionalities. Understanding their differences is crucial for writing clear and efficient Python code. As a Python developer, we must know when to use these for writing efficient code. In this article, we have explained their use cases with examples.

Difference Between (), {}, and [] in Python

How to Use Standard Parentheses in Python - ( )

Parentheses are used for multiple purposes in Python, The () operator is used to call a function and pass arguments, create tuples, and arithmetic expressions.

1. Function Calls: When we call a function, we use the `()` operator. For example, print().

Python
def greet():
    print("Hello, World!")

greet()  # Function call using ()

Output

Hello, World!

While calling a function, we can also pass function arguments in ().

Python
def greet(geek):
    print("Hello, ", geek, "!")

geek = "GFG Learner"
greet(geek)

The order of passing values matters. The first value gets assigned to the first function argument, second value to the second argument, and so on. To explicitly set value to a variable, we can assign value by referring its name. See the example below:

Python
def greet(geek, age, institue=""):
    print("Hello, ", geek, "!")
    print(f"Your age is {age}!")
    print(f"You are form {institue}")

geek = "GFG Learner"
greet(geek, 18, institue="Sanchaya Education")

# institute is optional
greet("Coder", 24)

Output

Hello,  GFG Learner !
Your age is 18!
You are form Sanchaya Education
Hello, Coder !
Your age is 24!
You are form

2. Tuples: Parentheses are used to define tuples, which are immutable collections of elements. For example, my_tuple = (1, 2, 3).

Python
my_tuple = (1, 2, 3)
print(my_tuple) 

Output

(1, 2, 3)

3. Grouping Expressions: Parentheses are also used to group expressions for controlling the order of operations.

For example, `result = (a + b) * c`. The expressions defined in () gets evaluated first.

Python
result = (2 + 3) * 4
print(result)  

Output

 20

How to Use Curly Braces in Python - { }

Curly braces are mainly used to define dictionaries and sets.

1. Dictionaries: In Python, dictionaries are collections of key-value pairs. They are defined using { }.

For example, my_dict = {"name": "MONU", "age": 25}`.

Python
my_dict = {"name": "MONU", "age": 25}

print(my_dict)
print("name=", my_dict['name'])
print("age=", my_dict['age'])

Output:

{'name': 'MONU', 'age': 25}
name= MONU
age= 25

2. Sets: Curly braces are also used to create sets, which are unordered collections of unique elements.

For example, my_set = {1, 2, 3, 3, 4}.

Python
my_set = {1, 2, 3, 3, 4}  # Duplicate values are automatically removed
print(my_set) 

Output:

{1, 2, 3, 4}
Note: To create empy sets in python use set(), my_set = {} will be an empty dictionary.

How to Use Square Brackets in Python - [ ]

Square brackets are used to define lists, indexing, and slicing.

1. Lists: In Python, lists are mutable collections of elements, and they are defined using `[]`.

Python
my_list = [1, 2, 3, 4]
print(my_list) 

my_list[0] = 10  # Changing the first item in the list
print(my_list) 

Output:

[1, 2, 3, 4]
[10, 2, 3, 4]

2. Indexing and Slicing: Square brackets are used to access elements in sequences like lists, strings, and tuples. For example, my_list[0] or my_string[1:4] .

Python
my_list = [10, 20, 30, 40]
print(my_list[1])   
print(my_list[1:3])

Output

20
[20, 30]

Difference Summary in Tabular Format

Symbol

Used For

Example

Mutable or Immutable

()

Tuples, Function Calls, Grouping Expressions

my_tuple = (1, 2, 3)

Tuples are immutable

{}

Dictionaries, Sets

my_dict = {"key": "value"}, my_set = {1, 2, 3}

Dictionaries and sets are mutable

[]

Lists, Indexing, Slicing

my_list = [1, 2, 3], my_list[0]

Lists are mutable

Conclusion

In conclusion, understanding the differences between parentheses (), curly braces {}, and square brackets [] in Python is essential for writing clear, efficient, and well-structured code. Parentheses are versatile, used for function calls, defining tuples, and grouping expressions. 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.


Article Tags :
Practice Tags :

Similar Reads