Data Types

Photo by Bram Naus on Unsplash

Data Types

·

3 min read

Update: The original article had some mistakes that have been corrected. Please point out any mistakes you see in my blog articles, and I will gladly correct them.

In the last article, I stated that we shall study variables. I think it is more important to understand data types and how they work. Let's dive into the water and look at how data types work.

Data types are like categories that help us understand the different kinds of information we use in programming. Imagine by analogy that you have a toolbox with different drawers. Each drawer is meant to hold a certain type of tool. For example, let's say we have a toolbox with three drawers: one for hammers, one for screwdrivers, and one for wrenches. Each drawer is specifically designed to hold the tools that belong in that category

Data types are like drawers that hold different types of information. Different data types in programming are like drawers holding different information types. An instance is the "string" data type which is used to hold text information like words and sentences, while the "integer" data type is used to hold whole numbers.

Kindly note that you should never confuse the data types you're working on within your program. Never put a hammer into the screwdriver toolbox. The same thinking applies to data types. You should never put a whole number into a "string" data type or vice versa.

Some examples of data types in Python

These are some of the few examples of data types in Python.

The int data type

This data type is used to represent whole numbers. In our example, the variable age is assigned the value of 30.

or

The float data type

This data type is used to represent decimal numbers. An example is the price of a product.

or

The str data type

This data type is used to represent text strings, like the name of a person. For example:

or

The bool data type

This data type is used to represent Boolean values, which can be either True or False. For example:

or

The list data type

This data type is used to represent an ordered collection of items, like a shopping list. For example:

or

There are more data types but for now, I believe these are the best to understand and work with. I will give explanations of other new data types as we continue learning Python.

In the next article, we shall look at variables and even convert string variables into integer variables. Stay tuned.