G-007_List_Tuple_Set_Dictionary.py
0.00MB
Feature | List | Tuple | Set | Dictionary |
Syntax | using square brackets [ ] |
using parentheses ( ) |
using curly braces { } |
using curly braces { 'key': 'value', 'key2': 'value2' } |
Example | [1, 2, 3] | (1, 2, 3) | {1, 2, 3} | {'name': 'Alice', 'age': 30} |
Mutability | Mutable | Immutable | Mutable | Mutable |
Ordered | Yes | Yes | No | Yes |
Allow Duplicates |
Yes | Yes | No | Keys: No, Values: Yes |
Methods | Many built-in methods - append( item ) - remove( item ) - sort( ) - pop( index ) |
Few built-in methods - count( item ) - index( item ) |
Many built-in methods | Many built-in methods |
Use Cases | Ordered, changeable collection |
Ordered, unchangeable collection |
Unordered, unique collection |
Key-value pairs |
Performance | General-purpose | Fast read access | Fast membership testing | Fast lookups with keys |
ps. lists don't directly support arithmetic operations
ex)
a = [1, 2, 3]
b = [3, 5, 7]
c = a + b
print( c) # output : [1, 2, 3, 3, 5, 7]
==> that's why we need to use NumPy.
'Python' 카테고리의 다른 글
Python_G-009. import vs from ... import vs from... import * (0) | 2025.01.17 |
---|---|
Python_G-008. Function (0) | 2025.01.16 |
Python_G-006. 10 Basic Plot (with Matplotlib) (0) | 2025.01.12 |
Python_G-005. Loop Type (0) | 2025.01.12 |
Python_G-004 : 10 basic operations & functions (0) | 2025.01.12 |