Takes a string, and returns a copy of that string in which all letters are uppercase. Numbers and symbols are not changed.
my_string = "shout"print(my_string)print(my_string.upper())
This would output:
Notice how the
.upper() method does not change the string it is used on.
.upper() method can be used to compare strings:
string1 = "Green Tigers"string2 = "gReEn tIgErs"if string1 == string2:print("These strings are already the same")elif string1.upper() == string2.upper():print("They are the same when you use the .upper() method")else:print("They are NOT the same")# Output: They are the already the same when you use the .upper() method
my_string = "amazing!"if my_string.upper() == "AMAZING!":print("Isn't that just " + my_string)# Output: "Isn't that just amazing!"
- Anonymous contributors
Learn Python on Codecademy
- Anonymous contributorsAnonymous contributors