5. Upper, lower, title

A method is a function attached to a value. You call a string method as text.method(...). These three methods take no arguments:

Strings are immutable: these methods do not change the original string, they return a new string.

title() treats every group of letters separated by a space or punctuation as a word. Case matters when comparing strings, so lower() is handy to compare answers regardless of how they were typed.

#01

Uppercase

upper() returns a new string with every letter in uppercase. It takes no arguments.

Print "python" in uppercase.

Print exactly:

Create a free account to save your progress and unlock chapter 2.

#02

Lowercase

lower() returns a new string with every letter in lowercase. It takes no arguments.

Print "PYTHON" in lowercase.

Print exactly:

Create a free account to save your progress and unlock chapter 2.

#03

Capitalize every word

title() makes the first letter of every word uppercase and every other letter lowercase.

Print "hELLo wORLD" with title().

Print exactly:

Create a free account to save your progress and unlock chapter 2.

#04

The original does not change

String methods return a new string; they never modify the original.

Create a variable named word with the value "Python". Print word in uppercase, then print word again on a second line.

Print exactly:

Create a free account to save your progress and unlock chapter 2.

#05

Compare without case

== compares strings exactly, so "YES" and "yes" are different. Converting the answer with lower() before comparing makes the check ignore case.

Create a variable named answer with the value "YES", then print whether answer in lowercase equals "yes".

Print exactly:

Create a free account to save your progress and unlock chapter 2.