Python Data Types
Python Data types are the classification or categorization of data
items. It represents the kind of value that tells what operations can
be performed on a particular data. Since everything is an object in
Python programming, Python data types are classes and variables
are instances (objects) of these classes. The following are the
standard or built-in data types in Python:
Numeric - int, float, complex
Sequence Type - string, list, tuple
Mapping Type - dict
Boolean - bool
Set Type - set, frozenset
Binary Types - bytes, bytearray, memoryview
Variables and data types in Python are related but are not the same concept.
Variables: are named containers or labels that store data values in memory. They act
as references to objects in Python. When you assign a value to a variable, you are
essentially telling the variable to point to that specific data object in memory.
Example:
my_age = 30 # 'my_age' is a variable
name = "Alice" # 'name' is a variable
Data Types: classify the kind of data that a variable holds. They define the nature of the
value stored and determine what operations can be performed on that data. In Python,
every value is an object, and every object has a type.
Example:
type(my_age) # This would return <class 'int'>
type(name) # This would return <class 'str'>
In summary:
A variable is the container or name that holds a value.
A data type describes the kind of value that is held within that container.
While variables are used to manage and access data, data types dictate the
characteristics and behavior of that data. In Python, variables are dynamically
typed, meaning a variable's type is determined by the type of the value it
currently references, and it can change if reassigned to a value of a different
type.