Python Basics — Data Types

Mehdi Lotfinejad
4 min readSep 19, 2022

In the previous lessons, you have learned what Python is, how to install Anaconda, and how to use Jupyter Notebook. In the first part of the Python Basics tutorial, we will focus on one of the core concepts in all programming languages: data types.

This tutorial is based on the hands-on training materials I have been teaching to data science trainees during these years. So, I am trying to help you think like a developer and improve your problem-solving skill. Alright, let’s get started.

What is an Algorithm?

An algorithm is a sequence of finite steps which is unambiguous and executable to solve a problem. “Finite steps” means that the steps will eventually lead to closure or completion. “Unambiguous” means these steps are crystal clear. “Executable” means that the algorithm statements can be replaced with programming language statements.

An algorithm is like the outline in an extended essay. Most people prefer to prepare the outline of the essay before writing the actual statements. It is useful for the writers to arrange their thoughts. In the same way, an algorithm is written before writing the actual code. The algorithm is not coding; it is just like a list of steps. It is like a series of instructions on vending machines to guide the users in buying foods and drinks.

An algorithm is not just a list of detailed steps. It is a list of detailed steps that humans can read and understand to carry out a task. It can be converted into code that a computer can read and understand to carry out a computing task.

What are comments in code?

Comments are essential to ensure that you and others can understand what your code is about. The Python interpreter is not read in, meaning you can write whatever you want, and the Python interpreter will ignore them. A good comment will be short, easy to read, and to the point.
To add comments to your Python code, you can use the hashtag (#). These comments are not run as Python code, so they won’t influence your result. Let’s put our first comments in the Python notebook:

# My first comment in Python

print("Hello, Python!") #this is my second comment

If you run the cell, you will notice that the Python interpreter ignored all the comments.

If you want to see the liner number of your code within a Jupyter Notebook cell you can press the Shift-L keys or alternatively you can go to View –> Toggle Line Number

What are Data Types?

Data types are essential to every program, and all programming languages support them. You use data types to define how to use values and how these values are stored in computer memory. Although there are many different data types in programming languages, there are four basic data types.

Data TypeSample ValueDescriptionInteger39An integer is a number with no decimal or fractional partFloat88.3Decimal numbersString“My name is Mehdi”A sequence of characters within single or double quotesBooleanTrue or FalseTrue or False values

Before we go any further, let's see what print() is. Almost all programming languages need the ability to display the result of the computation to users. In Python programming language, print() function does this job, and whatever is inside the parenthesis will be shown on the output.
We can even print multiple things in a single
print command; we just have to separate them using commas.

It would be helpful if we could identify the data type of each value in Python. The type() function in Python returns the data type of the object passed to it as an argument.

Let’s see how we can use type() function to identify the data type of different values.

Go ahead and run the cell in the Jupyter notebook; you will see the values and their data types on the output.

Strings are a set of characters, symbols, numbers, whitespace, and even empty space between two sets of quotation marks. In Python we can use either single or double quotes to create a string.

Alright, I hope you enjoyed this lesson, too. In the next part of this lesson, you will learn about variables in Python.

--

--

Mehdi Lotfinejad

Senior Data Scientist, Professional Trainer, and Content Writer @ Dataquest