Lesson 1 - String Manipulation - Hard
Lesson 1 - String Manipulation - Hard
String Manipulation
Lesson objectives…
❑ Be able to manipulate strings.
❑ Apply string manipulations to
different python tasks.
❑Understand the purpose of substrings
and length checks.
Video
Lesson theory video: https://youtu.be/gEJMBkArksg
String manipulation - Concatenation
Concatenation means ‘joining’.
The above code will give you an error, because you can’t add a
comma when storing a value in a variable because it will
count it as an argument. However you can concatenate using
“+” sign.
Correct way:
Index 0 1 2 3 4 5 6
number
Characters E N G L A N D
String manipulation – Substring
-1 is used to select the last character of a
string.
What do you think the following code will display?
country = "ENGLAND"
print(country[-1])
Index 0 1 2 3 4 5 6
number
Characters E N G L A N D
String manipulation – Substring – PYTHON
The following code will display: "EN"
country = "ENGLAND"
print( country [ 0 : 2 ] )
Start position
Up to but not included
Index 0 1 2 3 4 5 6
number
Characters E N G L A N D
Substring in the exam (pseudocode)
The following code will display: " LAND "
country = "ENGLAND"
print( country.substring(3,4) )
How many letters it will
Start position display
Index 0 1 2 3 4 5 6
number
Characters E N G L A N D
Substring in the exam (pseudocode)
What will the following code display?
country = “United States"
print( country.substring (1,3) )
How many letters it will
Start position display
Character U n i t e d S t a t e s
Substring in the exam (pseudocode)
What will the following code display?
country = “United States"
print( country.substring (3,3) )
How many letters it will
Start position display
Character U n i t e d S t a t e s
Substring in the exam (pseudocode)
What will the following code display?
country = “United States"
print( country.substring(7,6) )
How many letters it will
Start position display
print( quote.lower() )