In this tutorial, we’ll learn what Python string upper() method is and how to properly use it. We’ll go through multiple Python code examples to understand how upper() method works in Python.
Introduction: Python String upper() Method
This method is used to return a new string after converting all alphabets in a string to uppercase format.
Syntax of upper() Method
string.upper()
- Python string upper() method does not take any arguments.
- This method returns a string having all its alphabets converted to uppercase.
Example 1: Python String upper() Method applied on a String
strVal='PYTHON PROGRAMMING' print(strVal.upper()) print('this is python.'.upper()) print('python pRogramming'.upper()) print('PYThON3'.upper())
Output
PYTHON PROGRAMMING THIS IS PYTHON. PYTHON PROGRAMMING PYTHON3
We can see that Python string upper method has returned new strings after converting all the alphabets of the above specified strings to uppercase.
Example 2: upper() Method used in Python For Loop
listItems=['this','iS','@','pythON','ProgrAmmiNG','language.'] valStr='' for val in listItems: valStr=valStr+ val.upper()+' ' print(valStr)
Output
THIS IS @ PYTHON PROGRAMMING LANGUAGE.
Example 3: upper() Method Return Value
valStr='python programming LanguagE.' returnedValue=valStr.upper() print(returnedValue)
Output
PYTHON PROGRAMMING LANGUAGE.
We can see that Python string upper() method has returned a new string having all the alphabets converted to uppercase format.
Click here if you want to learn how to convert a string to lowercase format.
Conclusion
To conclude this tutorial, hope you now have a detailed practical understanding of how to properly use Python string upper method. I’d love to have your feedback on this post. Thank you for reading it.