You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
String manipulation means inspecting and transforming text data. Strings are one of the most commonly used data types, and being able to work with them is essential for GCSE Computer Science (AQA 3.2 / OCR J277 2.2).
A string is a sequence of characters. Each character has a position (index), starting from 0:
| Index | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Char | H | e | l | l | o | W | o | r | l | d | ! |
greeting = "Hello World!"
print(greeting[0]) # H
print(greeting[6]) # W
print(greeting[11]) # !
To find the number of characters in a string:
LEN("Hello") returns 5len("Hello") returns 5Note: Spaces, digits, and punctuation all count as characters.
A substring is a portion of a string. You extract substrings using slicing.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.