Data Types Examples: 46 Problems with Answers
Worked examples of Data Types to try before you open each solution, then practice problems with answers.
Worked Examples
Example 1
easyShow solution
Answer
First step
Full solution
- 2. Step 2: 'Hello' is text enclosed in quotes — this is a string.
- 3. Step 3: 3.14 has a decimal part — this is a float (real number). TRUE is a logical value — this is a boolean.
Example 2
mediumExample 3
easyExample 4
mediumExample 5
hardExample 6
hardExample 7
challengePractice Problems
Try each one, then open the solution to compare your method.
Example 1
mediumExample 2
hardExample 3
easyExample 4
easyExample 5
easyExample 6
easyExample 7
easyExample 8
easyExample 9
easyExample 10
easyExample 11
mediumExample 12
mediumExample 13
mediumExample 14
mediumExample 15
mediumExample 16
mediumExample 17
mediumExample 18
mediumExample 19
mediumExample 20
challengeExample 21
challengeExample 22
challengeExample 23
easyExample 24
easyExample 25
easyExample 26
easyExample 27
mediumExample 28
mediumExample 29
mediumExample 30
mediumExample 31
mediumExample 32
mediumExample 33
mediumExample 34
mediumExample 35
hardExample 36
hardExample 37
hardExample 38
hardExample 39
challengeWhat to focus on
Core idea: Operations depend on type: you can add numbers, concatenate strings.
Common stuck point: '5' (text) and 5 (number) are different—some languages convert automatically, some don't.
Ask yourself: Does the result depend on what kind of value it is, such as a number, text, or true/false?
Concept recap
Categories that classify data values and determine which operations can validly be performed on them. Common data types include integers, floating-point numbers, strings, booleans, and arrays, each with its own set of permitted operations.
Data types are like the units on a measuring jug and a ruler. Both show numbers, but adding 3 cups to 3 centimetres makes no sense, so you check what each number measures before combining them. A computer checks types the same way. The comparison stops at strings: text measures nothing, and joining two pieces of text just sets one after the other.
Read the full lesson on Data TypesBackground knowledge
These ideas may be useful before you work through the harder examples.