How would you convert a string into uppercase?
Use the upper() method. It returns a new string with all letters in capital. Like all string methods, it does not change the original string.
name = "david smith"
print(name.upper())
print(name.title())
print(name.capitalize())
Output:
Tutorials Class - Output Window
DAVID SMITH
David Smith
David smith
title() makes the first letter of every word a capital, and capitalize() changes only the first letter of the whole string. The opposite of upper() is lower(), explained in this question.
Learn more about the similar topics:
| Tutorials |
|---|
| Python Strings |
| Exercises & Assignments |
|---|
| Python program to check palindrome string |
| Python program to count vowels in a string |
| Python program to reverse a string |
| Interview Questions & Answers |
|---|
| How would you convert a string into lowercase? |
| How would you convert a string into uppercase? |
| Why do we use the join() function in Python? |
| What are f-strings in Python? |