Basic Data Types

Now, let’s discover the most basic data types that are available out there. These are:

  • Integers
  • Floating Point Numbers
  • Boolean Values
  • Strings
  • Characters

Integers

Let’s start with Integers, or Int for short. An Integer is nothing else but a whole number (i.e. 0, 1, 2, 50, -73, -101). It is usually used for counting. Or quantifying in discrete steps. In Python you assign an integer as follows:

value = 15
number_of_wheels = 4
height_in_cm = 10
x = 7

Floats

Next, a Floating Pint Number, or Float for short, is a number with a decimal part (i.e. with a decimal point). Floats are usually used to store continuous information such as measurement values. The decimal part still can be zero though. (Note that the decimal point is a dot and not a comma.)

temperature = 52.6
voltage = 4.692
a = 3.0

Booleans

The next category are Booleans, or Bools for short. A bool can only contain one of two values: True or False. They are usually used to describe the state of a binary property such as if a condition is true or if a device is turned on.

battery_is_full = True
motor_is_on = False

Strings

The next type are Strings, sometimes called Str. A string is basically a word or even a sentence. These words can be anything you like. Also, because Python would not know if you want to assign a word into a string variable or the value of another variable, you must specify the value inside quotes (‘ ‘) or double quotes (” “). There is no difference between the different types of quotes, but you are allowed to use a quote inside a sentence if it is the different kind of quotes that you use to specify the string (like ” it’s “).

greeting = "Hello Dave's RoboShack!"
robot_name = 'Shacky'

Characters

The last type is called a Character, or Char for short. It has pretty much the same properties like a string except that a char is maximum one letter long. Basically it is a string with one single letter.

initial = "D"
subject = 'B'

In Python, there is not really a use for chars. In C for example, a string is nothing else than a list of chars. (Lists are covered in the next part of this guide as they are already a little bit more complex data types.)

Note:

It is pretty easy to confuse strings and numbers. How? Let’s see:

a = 2
b = 3.5
c = '32'
d = "2.3"

In the examples above, it might seem clear which of these variables are strings and which are ints or floats due to the quotes. But if you work with them in a program, it is quite easy to oversee this which can turn into quite some headaches when debugging. Even though it looks like they are the same, they are not. Later, you will see how you can convert a string into a number type and the other way around to work with them.

Continue learning about complex data types or go back to revisit variables.