Mastering Length, Upper, Lower, and the tricky Substring.
Computers always start counting positions at 0, not 1. If you count from 1, you will lose marks on Substring questions.
Think of a String as a necklace of beads. Each bead is a character. Even a space counts as a bead!
Counts how many characters are in the string. Includes spaces and symbols.
Converts all letters to UPPERCASE (Shouting).
Converts all letters to lowercase (Whispering).
Substring cuts out a specific part of the word. In OCR Reference Language, you need two numbers:
Where do we start cutting? (Remember index 0!)
How many characters do we want to grab?
// Example: Grab "Put" from "Computer"
word = "COMPUTER"
part = word.substring(3, 3) // Start at 3 ('P'), take 3 letters
print(part) // Output: "PUT"
In Python, we use "Slicing" [start:end]. In OCR Exams, we use "Substring" (start, length).
Do not mix these up in the exam!
| Feature | OCR Reference Language | Python Code |
|---|---|---|
| Length | string.length | len(string) |
| Upper Case | string.upper | string.upper() |
| Lower Case | string.lower | string.lower() |
| Substring (The Hard One) |
string.substring(x, y)Start at x, take y characters. |
string[x:z]Start at x, stop before index z. |
A variable is declared: username = "Neo_The_One"
1. print(username.length)
11
2. print(username.substring(0, 3))
"Neo"
3. print(username.upper)
"NEO_THE_ONE"