Python supports different types of variables (datatypes) such as whole numbers, floating point numbers and text.

You do not need to specify the datatype of a variable, you can simply assign any value to a variable. Type the program below and start it.

Related course: Complete Python Bootcamp: Go from zero to hero in Python

Datatypes

The example below shows you several variables. These can be assigned as you wish. Once defined you can print them or use arithmetics.

#!/usr/bin/python

x = 3 # a whole number
f = 3.1415926 # a floating point number
name = "Python" # a string

print(x)
print(f)
print(name)

combination = name + " " + name
print(combination)

sum = f + f
print(sum)

You should see several lines containing numbers and text:

python on dos

Exercises

Try the exercises below

  1. Make a program that displays several numbers.
  2. Make a program that solves and shows the summation of 64 + 32.
  3. Do the same as in 2, but make it sum x + y.

After completing these continue with the next exercise.

Download answers