Predict 1
word = "robot" print(word.length)
PAPER 2 • 2.2.1 Programming Fundamentals • STRING HANDLING
String handling lets a program inspect, extract and transform text. OCR gives you tools such as .length, .substring, .left, .right, .upper, .lower, ASC and CHR.
Different OCR string commands help for different jobs. Some commands take part of a string, some change its case, and some convert between characters and ASCII values.
.length
Counts how many characters are in the string.
.substring
Extracts a section using a start index and number of characters.
ASC / CHR
Switches between a character and its numeric code.
Drag each term into the correct definition.
| Term | Definition |
|---|---|
| Gives the number of characters in a string. | |
| Extracts part of a string from a start index. | |
| Takes a chosen number of characters from the left. | |
| Takes a chosen number of characters from the right. | |
| Converts text into uppercase letters. | |
| Converts a character into its ASCII number. |
Sort each prompt into the group that makes the most sense.
Use the code to decide what each program will print.
word = "robot" print(word.length)
subject = "ComputerScience" print(subject.left(4))
print(CHR(65))
Read the task below and explain which string command fits each part best.
A school app stores the text "computer science". It needs to show the first four letters as a short code and then display the whole title in uppercase on a heading.
.left(4) is good for taking the first four characters, while .upper is best for changing the whole string into capital letters.
Create a record of your starter activity responses.