Python lesson
.upper() and .lower()
LAGOS, then lagos. city itself is still Lagos: the methods hand back a copy.
Try this lesson free →Example
Text methods give back a changed copy. .upper() makes capitals, .lower() makes small letters:
city = "Lagos"
print(city.upper())
print(city.lower())LAGOS
lagosKey points
.upper()A copy in capitals: LAGOS.
.lower()A copy in small letters: lagos.
city.upper()The method goes after the text it changes, joined by a dot.
Put together: print(city.upper()). To keep the change, store it: city = city.upper().
Practice
1. Build a line that shows city in capitals.
print(city.upper())2. Build a line that stores product in small letters in a variable called p.
p = product.lower()3. store holds abuja. Print it in capital letters.
store = "abuja"
print(store.upper())4. name holds TUNDE. Print it in small letters.
name = "TUNDE"
print(name.lower())5. Change code to capitals and store it back in code. Then print code.
code = "ab12"
code = code.upper()
print(code)Learn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.
Try this lesson free →