4Data Types

The next concept of Python that we will introduce is data types and in this chapter we will introduce a number of these and show how they behave when applied to some basic operators. We first start by introducing integers which are a number without a decimal point, written as follows:

image

A float is by definition a floating point number so we can write the previous as follows:

image

A string is simply something enclosed in either a double or single quote. So again we can rewrite what we have seen as follows:

image

Given the fact that we know how to define these variables, how can we check what they are? Well, conveniently Python has a type method that will allow us to determine the type of a variable. So we will rewrite what we have done and assign each instance to a variable and then see what type Python thinks they are

image

So now we can define the variables, the question is what can we do with them? Initially we will consider the following operations:

  • +
  • *
  • /

These are commonly known as the mathematical operation: addition, subtraction, multiplication, and division.

So let's ...

Get The Python Book now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.