Back to String Handling Operations In A Programming

Oak National Academy

Lessons written by expert teachers in England, each with slides, a video and quizzes.

Their topic:
Programming: strings and lists
For your topic:
String Handling Operations In A Programming · Computer Science - 9210

Use these lessons alongside our lesson note, which covers your syllabus in full.

What this covers in your syllabus

3 lessons from Oak National Academy

Lesson 1 of 3 · GCSE level, ages 14 to 16

String handling

By the end: I can use string handling techniques to find things out about a string.

Key learning points

  1. A string is a collection of characters.
  2. String handling is using techniques and built-in functions to find out information about strings.
  3. The len() function is used to return the length of a string.
  4. The index number is used to retrieve a single character from a specified position in a string.
  5. For loops can be used to iterate through some or all of the items in a string.

Keywords

string handling
how programs manipulate text through operations like joining, searching and formatting
index
the location of items or elements in a list, array or string
for loop
an iterative statement that will repeat for the length of a given sequence

A common mistake

Mistake: Operations in programs can only be performed on numbers.

In fact: Operations can be performed on different types of data. What the operator does can change depending on the data type it is being used with.

Check what you learned

From Oak National Academy's exit quiz. Choose every answer that is right.

What will `len("Quiz")` return?
What happens when you use a for loop with a string?
Which of these is not a valid operation on a string?
Which of the following is true about operations in Python?

A computing lesson by Oak National Academy licensed under the Open Government Licence (OGL) v3.0. Read the licence

Lesson 2 of 3 · GCSE level, ages 14 to 16

String manipulation

By the end: I can create a program using string handling techniques.

Key learning points

  1. The contents of a string can be validated.
  2. The random module can be used to generate random numbers and pick random letters from a string.
  3. Concatenation is a way of joining strings using the + operator to make a new string.
  4. Strings can be manipulated using the upper() and lower() string methods to convert the string into upper- or lowercase.

Keywords

random
a module that can generate random numbers, pick random items or shuffle a list
concatenation
the process of joining strings together to create a new string
lower()
a string method that converts all letters in a string to lowercase
upper()
a string method that converts all letters in a string to uppercase

A common mistake

Mistake: The random module will only generate random numbers.

In fact: The random module can generate random characters as well as numbers.

Check what you learned

From Oak National Academy's exit quiz. Choose every answer that is right.

What is the correct way to join the strings "blue" and "berry" into one word?
What must you include in your program to use the random library?
What will be printed by the following code? ```word = "Pinecone" print(word.upper())```
Which of the following correctly selects a random letter from the word "elephant"?
The random module generates ...

A computing lesson by Oak National Academy licensed under the Open Government Licence (OGL) v3.0. Read the licence

Lesson 3 of 3 · GCSE level, ages 14 to 16

Substrings

By the end: I can slice a string to create a substring and then use list methods on the substring.

Key learning points

  1. A substring is a part of a string.
  2. Slicing can be used to separate a string into substrings.
  3. ASCII is a character set used to represent all of the characters on a standard American or English keyboard.

Keywords

substring
part of a string
slice
the process of extracting a specific substring
ASCII
a character set that represents each character with a unique numerical value

A common mistake

Mistake: Indexing starts at 1 as that is the location of the first element.

In fact: In Python, and many other programming languages, indexing starts at 0.

Check what you learned

From Oak National Academy's exit quiz. Choose every answer that is right.

What is a substring?
What will the following Python code output? ```word = "HELLO" print(word[1:4])```
What is the correct syntax to extract the substring "pin" from "pineapple", which is stored in the variable fruit?
Which of the following statements about slicing in Python is true?
How do you check if the substring "apple" is in the string "pineapple"?
What does the following Python program do? ```char = input("Enter a character: ") print(ord(char))```

A computing lesson by Oak National Academy licensed under the Open Government Licence (OGL) v3.0. Read the licence

The wording comes from each publisher. The layout and the links to your syllabus are ours.