levo

Problem Solving with Programming

String handling

  • 3 things to know
  • Paper 2
Start revising · £5/month

Overview

len(), indexing and slicing, find() and index(), upper() and lower(), concatenation, split(), strip() and replace(), with worked outputs.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

State what is printed by print(len("Hello world")).

Key term

What character is word[2] when word = "Python"?

Key term

State what is printed by word = "computer", then print(word[3:6]).

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    State what is printed by print(len("Hello world")).

    Model answer

    The code prints 11. The space counts as a character.

  2. 2

    What character is word[2] when word = "Python"?

    Model answer

    The character is t. Indexing starts at 0, so index 2 is the third character.

  3. 3

    State what is printed by word = "computer", then print(word[3:6]).

    Model answer

    The code prints put. The slice starts at index 3 and stops before index 6.

  4. 4

    How can the last character of a string s be found using len()?

    Model answer

    The last character is s[len(s) - 1]. The indexes of a string run from 0 to one less than its length.

  5. 5

    What is printed by print("banana".find("an"))?

    Model answer

    The code prints 1. The find() method gives the index of the first match, counting from 0.

  6. 6

    How do find() and index() differ when the substring is not in the string?

    Model answer

    The find() method returns -1 when the substring is missing. The index() method raises an error instead, which crashes the program.

Other ways to work this

The same content, four other ways.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

Computational Thinking
Data
Computers
Networks

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

The check is 45 + 27 = 72.
denarybinaryhexadecimal

Blank Blitz consolidates the facts

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

A kibibyte (KiB) is 1,024 bytes. The figure 1,024 is 2¹⁰.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Problem Solving with Programming, on a schedule.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.