
PYTHON — Change Case Exercise Python
Talk is cheap. Show me the code. — Linus Torvalds
In this exercise, you will practice working with string methods in Python. The task is to write a program that converts a series of strings to lowercase and then to uppercase.
Here’s the code to accomplish this task:
# Define the strings
strings = ["Animals", "Badger", "Honey Bee", "Honey Badger"]
# Convert each string to lowercase and print
for string in strings:
print(string.lower())
# Convert each string to uppercase and print
for string in strings:
print(string.upper())In the code above, we start by defining a list of strings. We then use a for loop to iterate through each string in the list and apply the lower() method to convert the strings to lowercase. We print the lowercase strings using the print() function. Next, we again use a for loop to iterate through the list of strings and apply the upper() method to convert the strings to uppercase. We then print the uppercase strings using the print() function.
When you run the above code, the output will display the lowercase and uppercase versions of the strings, each on a separate line.
By completing this exercise, you’ll gain a better understanding of how to manipulate string cases in Python using string methods.






