String Methods (upper, lower, replace…), online

Six activities your students do on their own devices. See who's finished, and their scores.

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())

Discover other journeys with this module

What students will learn in this module

Every question in Module 31

Quick questions

  1. What does 'hello'.upper() return?A'HELLO'B'Hello'
  2. What does 'HELLO'.lower() return?A'Hello'B'hello'
  3. What does 'abc'.replace('b', 'x') return?A'axc'B'abc'
  4. Do string methods change the original string?ANo they return a new stringBYes
  5. 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 does
print('hello'.upper())Match it to what it does
print('hi'.replace('h','H'))Match it to what it does

Fill in the blanks

  1. name = 'hello'
    print(name._____())
  2. name = 'HELLO'
    print(name._____())
  3. msg = 'I like cats'
    print(msg._______('cats', 'dogs'))
  4. text = '  hi  '
    print(text._____())
  5. 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')