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
Example 2.4.1 - Output14
- Float - A float is a number that has a decimal point.
Example 2.4.2
Example 2.4.2 - Output19.99
- String - A string is a sequence of characters enclosed in quotes (single or double).
Example 2.4.3
Example 2.4.3 - OutputKim
- Boolean - A boolean is a type that can hold one of two values: True or False.
Example 2.4.4
Example 2.4.4 - OutputTrue
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.