The difference between `list()` and `[]` lies in their usage and purpose in Python.
list():
- `list()` is a built-in Python function used to convert an iterable object into a list. It takes an iterable object (such as a tuple, string, or range) as an argument and returns a new list containing the elements of that iterable.
- Example: `list((1, 2, 3))` will return `[1, 2, 3]`.
[ ] (square brackets):
- Square brackets, also known as list literals, are used to directly create new list objects in Python. This is the most straightforward and commonly used method for creating new lists.
- Example: `[1, 2, 3]` will create a new list containing the elements `1`, `2`, and `3`.
In summary, `list()` is a function used to convert iterable objects into lists, while `[]` is a syntax for directly creating new list objects.
def solution (a,b):
result = list(range(a,b))
return result
print(solution(1,4))
#Result = [1, 2, 3]
def solution(a, b):
result = [num for num in range(a, b)]
return result
print(solution(1, 4))
# result = [1, 2, 3]
'Issue Note' 카테고리의 다른 글
The count of divisors and addition (0) | 2024.04.09 |
---|---|
Difference between 'num for num in range' and 'for num in range' (Python) (0) | 2024.04.02 |
DATE - [SQL} (0) | 2024.04.01 |
Exclusion of NULL values in b.customer_id column in SQL query [SQL] (0) | 2024.03.22 |
Table name from Subquery [SQL] (0) | 2024.03.21 |