In the same way, when coding, we encounter different types of data. Python uses labels, known as data types, to identify and handle the kind of data it’s dealing with. Sometimes, we specify the data type by using specific syntax when storing a value. Other times, we can instruct Python to interpret certain data in a particular way using built-in functions.
Data types supported by Python
Python offers a variety of data types, each designed to cater to specific needs. These data types can be categorized as follows:
Numeric data types
Integers
Floating-point numbers
Complex numbers
Collection data types
Sequential collections
Strings (text)
Lists
Tuples
Unordered collections
Boolean data
Let's dive into these types, exploring what they store, why they're useful, and how to use them.
Numeric data types
Numeric data types are used to store numbers. They can be of three types, integers, floating-point numbers, or complex numbers.
Integers
The integer data type is used for whole numbers, like 5, -12, or 0. Integers are used when you need to count things as the number of items in a list or the iteration count in a loop.