Reputation: 1
So I am working with the string method s.upper()
, but when it executes it does not convert the whole sentence to uppercase. I am wondering if my understanding is wrong or I am doing something wrong.
I tried using the s.lower
method and it gave me the same display with nothing changed.
Here is my code:
foods = ['soup', 'waffle', 'pizza']
for food in foods:
food[0].upper()
print(foods[0], foods[1], foods[2])
The code displays :
soup waffle pizza
when I expected
SOUP WAFFLE PIZZA
Upvotes: 0
Views: 27
Reputation: 3195
Here's a simple example that should elucidate the problem:
food = 'Soup'
food.upper()
print(food)
>>> 'Soup'
When you called food.upper()
, it returned SOUP
, but you didn't do anything with the result. Instead, you need to assign the result to something.
food = 'Soup'
food = food.upper()
print(food)
>>> 'SOUP'
This time, since you assigned the result of the call to food.upper()
back to the variable food, it now has the value SOUP
which you see when you print it.
Upvotes: 1