Intern
How to convert a string to uppercase or lowercase?
sobes.tech AI
Answer from AI
The built-in string methods .upper() and .lower() are used.
# Example of converting to uppercase
my_string = "hello world"
upper_string = my_string.upper()
# upper_string is now "HELLO WORLD"
# Example of converting to lowercase
another_string = "HELLO PYTHON"
lower_string = another_string.lower()
# lower_string is now "hello python"
Comparison table:
| Method | Description | Input example | Result |
|---|---|---|---|
.upper() |
Converts all characters in the string to uppercase. | "test STRING" |
"TEST STRING" |
.lower() |
Converts all characters in the string to lowercase. | "Test STRING" |
"test string" |