Skip main navigation

New offer! Get 30% off one whole year of Unlimited learning. Subscribe for just £249.99 £174.99. New subscribers only T&Cs apply

Find out more

Python data types

Python data types
0.2
(upbeat music) When you program in Python, the information you provide to the computer is referred to as data. The first of our basic data types are numbers including integers, for example, four or minus 222. Real numbers or decimal numbers, which have a floating decimal point are called floats, such as 3.14.
25.5
Complex numbers are also catered for. Here j is assigned to be the square root of minus one. Besides numbers you also have strings which resemble words. Each string is composed of elements or letters, and they’re defined using quotation marks, such as name and surname, or even a space, which is an empty character. The next data type may be slightly less familiar to you. This is a Boolean data, which can either be true or false. For example, you can test whether the variable name equals Mark by calling the bool function, which evaluates the name equals Mark as true or false. In this case, it returns true. Let’s practice with these basic data types in Jypter notebook.
72.4
Follow the commands in the video, and practice them on your notebook. In the first cell you’ll practice with the basic numerical data types starting with integers. Here you have an integer data four. When you assign variables in Python, in this case the number four is stored in memory and the variable name n points towards that location in memory. Pause the video and add them to your Jypter notebook. Now you have created four objects in memory and the variable names point towards these locations in memory. As you define these variables in memory, the variable names enter the namespace. You can provide an overview of this namespace in Python with the command whos.
116.8
Run the command and see what variables are being defined in memory, what type, and in some cases how much memory these variables are using. Creating string data types is relatively similar. In this case, instead of numerical data you have characters for letters or symbols. And again, as with numbers our human readable data is converted to binary data forms and is stored in the computer’s memory. Pause the video and add them to your Jypter notebook. With strings you can join them or concatenate them together using the plus operator. Here you’ll create a variable called full, which contains the surname, first name and a space between them.
164.4
Again, calling the function whos should show that these new string variables have been added to memory. Next, let’s practice with a simple Boolean example. Here you’ll use the function bool to evaluate whether a statement is or false. You’ll assign a variable b to our very obvious statement. Is one equal to one? Yes, it is. Pause the video and add them to your Jypter notebook. In our next example, you can show that you can easily combine the print statement and Boolean function statement in one line. So you can test, for example is our variable n equal to two? No, it’s not. It’s false and was defined as equal to four.
210.2
If you experiment, you can also test if p is equal to 3.14. It is, so it’s true. It’s a very simple function and you’ll find a place for it in solving different problems when you want to check the value of a variable and act on whether that variable is true or false. Using all these built-in data types and functions will become much clearer as you start using Python for your data analysis.

Each and every value belongs to a specific data type in Python. Data type defines the type of data values a variable can contain and the operations that can be performed on that data.

The video introduced you to the data types built into Python and showed you examples of each data type and its syntax in the Jupyter Notebook.

Next, you will engage in an exercise to apply your knowledge about Python data types.

This article is from the free online

Introduction to Data Analytics with Python

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now