= 12
a = 7.3
b print("A:", a, type(a))
print("B:", b, type(b))
A: 12 <class 'int'>
B: 7.3 <class 'float'>
In Python we have several built-in data types. The most common types of data that you will find are numbers, strings and booleans.
Description | Type | Example |
---|---|---|
integers or whole numbers | int | a = int(12) |
floating-point numbers | float | b = float(7.3) |
= 12
a = 7.3
b print("A:", a, type(a))
print("B:", b, type(b))
A: 12 <class 'int'>
B: 7.3 <class 'float'>
Description | Type | Example |
---|---|---|
textual data (strings) | str | a = “Jean Golding” |
= "Jean Golding"
name print("Name:", name, type(name))
Name: Jean Golding <class 'str'>
Description | Type | Example |
---|---|---|
boolean values (True or False) | bool | a = True |
= 23
a = 2
b print(a != b)
True
We can assign this boolean value to a variable:
= (a != b)
c print("c:", c, type(c))
c: True <class 'bool'>
Note the use of the brackets around a != b
. This isn’t necessary here, but it can help to make the code clearer!