Data Types

Python Programming — 2 minute read

Programming languages manipulate data and then display it as information. That is all they do. They enable us to create software that solve real-world problems from everyday tasks to complex scientific calculations. At the core of every problem, we are simply managing data.

To start with, we are going to introduce the idea of of Data Types. As mentioned before, computers are very stupid, we need to explicitely tell them what type of data we are storing in their memory so that they know how to handle it.

You only need to know 6 data types:

Data types are used to define what type of data a variable holds. Variables can change the data and the type of data they hold.

Initialisation is the act of setting a variable for the first time. Setting a variable in Python is easy:

my_variable = 5

The part on the left is the name of the variable (this cannot contain any spaces) and the part on the right is the value we assign to it. In this case, the Integer 5.

An description of each data type is provided below.

Characters

A character, often referred to as a char, is a single ASCII letter stored in a byte.

Python is so high level that it does not support characters. If you need to define a character for any reason, you can initialise it like this:

my_character = 'a'

Although characters do not exist in Python, they do exist in lower level programming langauges such as C. This is where our next data type comes in.

Strings (str)

A string or str is a

In low level languages such as C, there is no built in string data type. You would have to create a list (a string) of characters to represent anything more than just a single character.

Fortunately, in Python, you can initialise a string very easily:

my_string = "this is my string"

Integers (int)

An integer or int is a whole number. Meaning there is no decimal.

You can initialise an integer as such:

my_integer = 1

Float (float)

A