How Can We Help?
In this tutorial, we will explain how to use Python string upper() method with basic syntax by example for better understanding.
How to Make String uppercase in Python? To make a string uppercase in Python, we use the upper() method. The upper method in Python converts all characters of a string to be in uppercase. It returns a copy of the original string.
Syntax:
<string_value/string_variable>.upper()
Input Parameters:
- string_value / String variable : The string that we want to convert it to uppercase.
String Uppercase All Characters
We can convert all string characters to uppercase in python by using the upper() method.
Example (1)
msg= 'wELCOME TO python'
print('Lowercase: ',msg.upper())
Output of example (1)
Uppercase: welcome to python
In the above example, in the value of string variable ‘msg’; ‘W’ and ‘PYTHON’ are lowercase. Using msg.lower() in the print statement, we have converted them into uppercase.
Python String Uppercase First Letter
We can convert the first letter of a string to uppercase in python using the upper() method and string slicing.
Example (2)
msg = "learnpythonwithoraask"
# Using lower() + string slicing
# Lowercase the first character of a String
result = msg[0].upper() + msg[1:]
# printing result
print("Uppercase the initial character : " + result)
Output of example (2)
Uppercase the initial character : Learnpythonwithoraask
In the above example, in the string variable’s value, the first character of the letter is in lowercase, and by using msg[0].upper() along with string slicing, we have converted the first character whose index is 0 to lowercase.
Note: An easy alternative to this solution is to use Capitalize() method.
In this tutorial, you have learned the string upper() method in Python. What is it? And how to convert all character of given string to uppercase.
Hopefully, it was clear and concise.
If you have an inquiry or doubt, don’t hesitate to leave them in a comment. We are waiting for your valuable feedback.
Similar Python String Formatting Methods:
- title() : It returns the “title cased” version of string means all the words start with uppercase and the remaining are lowercase.
- center() : It returns a space-padded string with the original string centered to a total of width columns.
- swapcase() : It inverts the case of all the characters in a string.
- lower() : It converts all the characters of a string to lowercase.
- rstrip() : It removes particular character of a string from right side.
- lstrip() : It removes particular character of a string from left side.
- strip(chars) : It removes particular characters of a string from left and right side.
- ljust() : It returns an original string with a filled specific character or space at the left side of the string value to justify the string’s new length (width).
- rjust() : It returns an original string with a filled specific character or space at the right side of the string value to justify the string’s new length (width).
- zfill() : It returns an original string value with filled zero at the left side of the string value to justify the string’s new length (width).
Related Articles
Python String – Mastering By Practical Examples (Comprehensive Guide)
Python tutorials list:
- Python tutorials list : access all python tutorials.