String Methods (upper, lower, replace…), online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
String Methods (upper, lower, replace…) in one minute
What students need to know
.strip() removes leading and trailing whitespace from the string. .split(',') splits the string at each comma into a list.
upper() converts every character to uppercase. replace() swaps every occurrence of the first arg with the second.
Mistakes students make
- upper() returns a new string: must assign it back or print directly.
- Method names are lowercase: upper(), not Upper().
- upper() is a string method: use name.upper(), not upper(name).
- replace() needs two arguments: old and new.
PREVIOUS · MODULE 30Strings – Slicing
YOU ARE HERE · MODULE 31String Methods (upper, lower, replace…)
NEXT · MODULE 32String Formatting (.format())
What students will learn in this module
Every question in Module 31
Quick questions
- What does 'hello'.upper() return?A'HELLO'B'Hello'
- What does 'HELLO'.lower() return?A'Hello'B'hello'
- What does 'abc'.replace('b', 'x') return?A'axc'B'abc'
- Do string methods change the original string?ANo they return a new stringBYes
- What does ' hi '.strip() return?A' hi 'B'hi'
Key terms
Students type the meaning of:
.upper().lower().replace(old, new).strip()
Match the pairs
name = 'hello' name.Upper()Match it to what it does
'hello'.replace('l')Match it to what it does' hi '.strip()Match it to what it does'a,b,c'.split(',')Match it to what it doesprint('hello'.upper())Match it to what it doesprint('hi'.replace('h','H'))Match it to what it doesFill in the blanks
name = 'hello' print(name._____())
name = 'HELLO' print(name._____())
msg = 'I like cats' print(msg._______('cats', 'dogs'))text = ' hi ' print(text._____())
csv = 'a,b,c' print(csv._____(','))
Spot the error
Question 1
Aname = 'hello'Bname.upper()Cprint(name)Dprint('Done')
Question 2
Aname = 'hello'Bresult = name.Upper()Cprint('Result:', result)Dprint('Done')
Question 3
Aname = 'hello'Bresult = upper(name)Cprint('Result:', result)Dprint('Done')
Question 4
Amsg = 'hello'Bresult = msg.replace('l')Cprint('Result:', result)Dprint('Done')
Question 5
Adata = ' hi 'Bcleaned = data.stripCprint('Cleaned:', cleaned)Dprint('Done')
