Welcome to the World of Data Types!
Hi there! Before you start writing complex programs, you need to understand the basic building blocks of information. Think of data types as different shaped containers. You wouldn't try to put a liter of milk into a flat envelope, right? Similarly, computers need to know exactly what "shape" your data is so they know how to store it and what they can do with it.
In this guide, we will break down the essential data types you need to know for your Oxford AQA exam. Don't worry if it seems like a lot to remember—by the end of this, it will feel like second nature!
1. What is a Data Type?
A data type is a classification that tells the computer what kind of value a variable holds. It determines two main things:
1. How much memory the data needs.
2. What operations can be performed on it (for example, you can multiply two numbers, but you can't multiply two names!).
2. The Essential Data Types
The syllabus requires you to understand and use these six specific types. Let's look at them one by one.
Integer
An Integer is a whole number. It can be positive, negative, or zero, but it never has a decimal point.
Real-world examples: The number of students in a class (25), your age (17), or a score in a video game (500).
Memory Trick: Think of the "I" in Integer as a "1"—a whole number!
Real / Float
While some languages call it a Float (short for "floating point"), the syllabus also uses the term Real. These are numbers that do have decimal points.
Real-world examples: The price of a chocolate bar (1.50), your height in meters (1.75), or the value of Pi (3.14).
Common Mistake: Using an Integer for money. Always use a Real/Float for prices because they almost always need decimals!
Boolean
A Boolean is the simplest data type. It can only ever be one of two values: True or False.
Real-world examples: Is the light on? (True). Is the user logged in? (False).
Analogy: Think of a Boolean like a standard light switch. It is either UP or DOWN; there is no middle ground.
Character
A Character is a single letter, digit, or symbol. It is usually represented inside single quotes in many languages.
Real-world examples: 'A', '7', '$', or even a space ' '.
String
A String is a sequence of characters. Think of it as a "string" of beads, where each bead is a character. Strings are used for text.
Real-world examples: "Hello World", "Computer Science", or even a phone number "0123456789" (we use a string here because we don't plan to do math with the phone number!).
Date / Time
This type is used to store specific moments in time or calendar dates.
Real-world examples: 25/12/2024 or 14:30:00.
Quick Review: The "Big Six"
• Integer: Whole number (10)
• Real/Float: Decimal (10.5)
• Boolean: True/False
• Character: Single symbol ('A')
• String: Text ("Hello")
• Date/Time: Calendar/Clock info (01/01/2025)
3. Changing Types (Casting)
Sometimes, you receive data as one type but need it as another. For example, when a user types their age into a computer, the computer often sees it as a String ("17"), but you need it as an Integer (17) to check if they are old enough to vote. This process is called conversion or casting.
According to your syllabus, you should be able to convert between:
• String to Integer: "123" becomes 123
• String to Float: "12.5" becomes 12.5
• Integer to String: 100 becomes "100"
• Float to String: 9.99 becomes "9.99"
• Date/Time to String: Making a date readable in a sentence.
• String to Date/Time: Turning typed text into a calendar format.
4. Working with Strings
Since strings are such a common data type, you need to know how to handle them. Here are the operations you must be familiar with:
• Length: Finding out how many characters are in a string (e.g., "Apple" has a length of 5).
• Position: Finding where a specific character is (e.g., in "Apple", 'A' is at position 0).
• Substring: Taking a small part out of a larger string (e.g., taking "App" out of "Apple").
• Concatenation: Joining two strings together (e.g., "Hello " + "World" = "Hello World").
5. Character Codes
Did you know? Computers don't actually understand letters! They only understand numbers (binary). Every Character has a secret number code assigned to it.
• Character to Character Code: Converting 'A' into its number (In ASCII, 'A' is 65).
• Character Code to Character: Converting the number 65 back into 'A'.
Tip: You will learn more about this in the "Representing Data" chapter, but for now, just remember that every key on your keyboard has a unique number associated with it.
Summary: Key Takeaways
1. Context Matters: Choose the data type that best fits the information you are storing to save memory and prevent errors.
2. Integers vs. Reals: If you need to count it, use an Integer. If you need to measure it, use a Real.
3. Booleans are Logic: Use Booleans for any "Yes/No" or "On/Off" situation in your code.
4. Strings are Collections: A String is just a collection of Characters joined together.
5. Type Hinting: If you are using Python, you can use "Type Hints" (like age: int = 17) to help keep track of your data types, though the exam doesn't strictly require you to write them.