python-for-j277 / getting-started · Lesson 04
Lesson 04 — Getting started
Data Types
The four basic types of value, and how to check them.
Every value in Python has a type. The type tells you what you can do with a value. For GCSE you need four of them.
The four basic data types
| Type | What it stores | Examples |
|---|---|---|
String (str) | Text, written in quotes | "hello", "B", "14" |
Integer (int) | A whole number | 14, -3, 0 |
Float (float) | A number with a decimal point | 1.62, 3.0, -0.5 |
Boolean (bool) | One of two values only | True, False |
Checking a type with type()
print(type("hello"))
print(type(14))
print(type(1.62))
print(type(True))Output
<class 'str'> <class 'int'> <class 'float'> <class 'bool'>
How it works
type()tells you the data type of a value.stris text,intis a whole number,floathas a decimal point,boolis True or False.
Booleans: True and False
is_logged_in = True
has_paid = False
print(is_logged_in)
print(type(has_paid))Output
True <class 'bool'>
How it works
- A boolean stores one of just two values:
TrueorFalse(note the capital letters). - Booleans are how a program records a yes/no fact.
- They become very important for making decisions — the next topic.
Quotes change the type
14 is an integer, but "14" is a string. They look the same on screen but behave differently: "14" + "14" gives '1414', while 14 + 14 gives 28.Remember the four
str, int, float, bool. Picking the right type prevents errors and surprises.What you have learned
- Every value has a type:
str,int,floatorbool. - Use
type()to check a value's type. - A boolean is either
TrueorFalseand records a yes/no fact. - Quotes make a value a string, even when it looks like a number.