ICT7Slides
ICT7Slides
Learning objectives
In this lesson you will learn to:
© Pearson Education Ltd 2020. Copying permitted for purchasing institution only.
Y10-02-CT7: String manipulation, string methods
Strings
Strings are sequences of characters.
They can contain any standard keyboard character (letters, numbers,
and punctuation marks).
In Python, you declare strings by placing “ “ or ‘ ‘ around the text.
You can work with strings in a number of ways, including printing
them to the screen, as in this example.
© Pearson Education Ltd 2020. Copying permitted for purchasing institution only.
Y10-02-CT7: String manipulation, string methods
String indexing
As strings are sequences of characters, you can treat each of the
characters separately using the index of the character.
Indices are the position of the character within the string, starting from 0.
Let’s use the example below to look at how this works.
Index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Characte C o m p u t e r S c i e n c e
r
© Pearson Education Ltd 2020. Copying permitted for purchasing institution only.
Y10-02-CT7: String manipulation, string methods
String indexing
© Pearson Education Ltd 2020. Copying permitted for purchasing institution only.
Y10-02-CT7: String manipulation, string methods
String slices
© Pearson Education Ltd 2020. Copying permitted for purchasing institution only.
Y10-02-CT7: String manipulation, string methods
Concatenation
You can also join strings together using the + operator.
firstString = "str"
secondString = "ing"
finalString = firstString + secondString
print(firstString)
print(secondString)
print(finalString)
str
ing
string
© Pearson Education Ltd 2020. Copying permitted for purchasing institution only.
Y10-02-CT7: String manipulation, string methods
Library functions
© Pearson Education Ltd 2020. Copying permitted for purchasing institution only.
Y10-02-CT7: String manipulation, string methods
© Pearson Education Ltd 2020. Copying permitted for purchasing institution only.
Y10-02-CT7: String manipulation, string methods
In action
© Pearson Education Ltd 2020. Copying permitted for purchasing institution only.
Y10-02-CT7: String manipulation, string methods
© Pearson Education Ltd 2020. Copying permitted for purchasing institution only.