a = 12
b = 7.3
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) |
a = 12
b = 7.3
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” |
name = "Jean Golding"
print("Name:", name, type(name))Name: Jean Golding <class 'str'>
| Description | Type | Example |
|---|---|---|
| boolean values (True or False) | bool | a = True |
a = 23
b = 2
print(a != b)True
We can assign this boolean value to a variable:
c = (a != b)
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!