2.4 Different types of variables

In Python there are different types of variabes but for this course we will be focusing on the following types:

  • Integer - An integer is a whole number without a decimal point.

Example 2.4.1

age = 14
print(age)
Example 2.4.1 - Output

14

 

  • Float - A float is a number that has a decimal point.

Example 2.4.2

price = 19.99
print(price)
Example 2.4.2 - Output

19.99

 

  • String - A string is a sequence of characters enclosed in quotes (single or double).

Example 2.4.3

name = "Kim"
print(name)
Example 2.4.3 - Output

Kim

 

  • Boolean - A boolean is a type that can hold one of two values: True or False.

Example 2.4.4

is_student = True
print(is_student)
Example 2.4.4 - Output

True

 


 

Exercise 2.4.1 - Write a Python program by creating two variables. The first variable should hold your age and the second variable should hold your nationality. Finally print both values on two separate lines.

You can refer to Output topic if you need help with the print() function.

Exercise 2.4.1 - Model Answer - Make sure to work out the exercise before checking the model answer.