In Python, `{}` curly braces are used to represent a dictionary.
A dictionary is a data structure consisting of key-value pairs. Inside the curly braces, key-value pairs are listed, separated by commas.
For example:
my_dict = {'name': 'John', 'age': 30, 'city': 'New York'}
Here, 'name', 'age', and 'city' are keys, while 'John', 30, and 'New York' are their corresponding values.
`()` parentheses are used to define functions or for function calls.
For example:
def my_function():
print("Hello, world!")
my_function() # Function call
Parentheses are also used to represent tuples. A tuple is an immutable sequence of data. Values inside parentheses are separated by commas.
my_tuple = (1, 2, 3)
`[]` square brackets are used to represent lists. A list is a mutable sequence of data. Values inside square brackets are separated by commas.
my_list = [1, 2, 3]
So, in Python, `{}` represents dictionaries, `()` are used for function calls and tuples, and `[]` denote lists.
'Study Note > Python' 카테고리의 다른 글
7. F-strings & Try Except (0) | 2024.03.27 |
---|---|
6. Set & tuples and list (0) | 2024.03.27 |
4. Function [Def] (0) | 2024.03.26 |
3. IF & loop (0) | 2024.03.25 |
2. List & dictionary (0) | 2024.03.25 |