This lecture explores the core components of Python’s data handling capabilities, focusing on how and why these types are used in data science.
Python categorizes data into two main types:
Values: Singular items like numbers or strings.
Collections: Groupings of values, like lists or dictionaries.
Mutable: Objects whose content can be changed after creation.
Immutable: Objects that cannot be altered after they are created.
Category | Mutable | Immutable |
---|---|---|
Values | - | int , float , complex , str |
Collections | list , dict , set , bytearray |
tuple , frozenset |
int
)x = 5
x
without creating a new int
.float
)y = 3.14
float
.str
)s = "Data Science"
s
requires creating a new string.list
)my_list = [1, 2, 3]
tuple
)my_tuple = (1, 2, 3)
set
)my_set = {1, 2, 3}
frozenset
)my_frozenset = frozenset([1, 2, 3])
dict
)my_dict = {'key': 'value'}
Understanding these basic types is crucial for data handling and manipulation in Python, especially in data science where the type of data dictates the analysis technique. As we move into more advanced Python we will get to know more complex data types.
For more information, you can always refer to the Python official documentation.