Lesson 5: Data types
Data types
Data can be referred to as different types. If it is known what type the data is, different operations can be performed on it. For example, you can add up a number but not text. If you’ve used Excel think of how a cell could contain a number, some text, or a date, for example.
Data generally falls into the following categories:
Data Type | Explanation | Example | Example Uses | |
---|---|---|---|---|
Numeric | Integer | A whole number | 23 | The number of items in a shopping cart |
Decimal/float | Where more precision is needed | 100.54 | The weight of a parcel | |
Text | Character | A single character | 8 | |
String/Text | Multiple characters making up some text | Hello World! | The name of a product | |
Boolean | Boolean | Represents true or false | FALSE | Whether a book has been read |
Date and Time | Date | A date | 01/12/1954 | A birthdate |
Timestamp | A date and time | 15:35:50:321 30/01/2020 | The date and time a purchase was made |
A String is a common datatype, made up of characters. Can you spot the two Strings in the following code example?
Code Examples
fruit = "banana" print("The fruit is: ", fruit)
Resources