Intro to Data Types#
Overview#
A data type defines what information you can save, and understanding different data types is crucial for a good code because each data type has its own set of operations.
Examples of Python data types:
Numeric Types: Integers (
int
), floating-point numbers (float), and complex numbers (complex)Text Type: Strings (
str
) represent sequences of characters enclosed in single quotes (‘’) or double quotes (“”)Boolean Type: Boolean (
bool
), which represents either True or False valuesSequence Types: Lists (
list
), tuples (tuple), and range objects (range)Set Types: Set (
set
) and frozenset (frozenset), which represent unordered collections of unique elements.Mapping Type: Dictionary (
dict
), which stores key-value pairs.None Type:
None
, which represents the absence of a value or a null value.
Find the type#
Everytime we assign a value to a new variable, we are also indicating the data type. You can use “type()” function to identify the data type of specific variable.
# Define variables
reservoir_name = "Ross Reservoir"
print(type(reservoir_name))
<class 'str'>
depth_ft = 279
print(type(depth_ft))
<class 'int'>
min_width_mi = 91.0
print(type(min_width_mi))
<class 'float'>
is_lake = True
print(type(is_lake))
<class 'bool'>
Important
Python is a dynamically typed language, which means that variables can change their data type during runtime based on the assigned value