Introduction
Displaying values
Variables
The print function
11. Integers, strings and floats
List basics
Summary

Instruction

Okay! Just like there are various types of cells in Excel (numbers, dates, text, etc.), there are various types of variables in Python. These include:

  • integers (int) - integer numbers

    current_age = 5
  • floats (float) - numbers with a decimal part introduced after a dot (.)

    current_weight = 75.5
  • strings (string) - text values surrounded by single (' ') or double (" ") quotes:

    standard_greeting = 'My name is Tom!'
  • Unlike many other programming languages, Python automatically detects the type of variable it should use. For instance, if you type:

    temperature = 36.6

    Python will know the temperature variable is a float because the number contains a dot (.). Take a look at another example:

    ratio = 250/100

    In this case Python will automatically detect that the result of division is a floating point number.

Exercise

In Python, there is a function named type() that can tell you the type of a variable that you pass in to its parentheses. Now, take a look at the template code and run it.

You can see that:

  • age is an integer (int),
  • weight is a float because it contains a decimal point (.),
  • name is a string (str) because it is surrounded by quotes.

Stuck? Here's a hint!

Simply run the template code.