Strings consist of letters or characters. Characters can be upper or lowercase. Python provides functions in order to make strings uppercase or lowercase or making the first letter uppercase and other lowercase etc. In this tutorial, we will learn how to make strings uppercase?
upper() Method Syntax
upper() is a method provided by string data or variable types. So it is a builtin method and we do not need to load any module. It has also very simple syntax where it does not accept any parameter and returns given string value as uppercase.
STR.upper()
- STR is a string data or variable which will be returned as uppercase with the upper() method.
Make String Value and Variable Uppercase
As a simple method it can be used easily by executing on the given string variables or values. The uppercase string will be returned and should be set into a new variable or directly used.
a = "WiseTut".upper()
print(a)
print("wisetut".upper())
b = "wisetut123"
print(b.upper())
print("test".upper())

Check If Specified String Is Uppercase
We can use the upper() method in order to make given string and all of its characters uppercase. But if we need to check if specified string value or variable uppercase we can use isupper()
method. If the given string value or variable is completely uppercase it will return true, if there is at least single lowercase character it will return false.
print("test".isupper())
print("Test".isupper())
print("TEST".isupper())
print("test123".isupper())
print("TEST123".isupper())

Check If Specified String Is Lowercase
We can also check if given or specified string value or variable is lowercase by using the islower()
method. We will
print("test".islower())
print("Test".islower())
print("TEST".islower())
print("test123".islower())
print("TEST123".islower())

Make List Items Uppercase
Python list is a special type where multiple items can be specified in a single structure or variable. Python list can contain a string, integer, float, object, etc. data types. We can also make a string type list items uppercase.
mylist = [ 'wisetut' , 'Wisetut' , 5 ]
newlist = []
for i in mylist:
if type(i) is str:
newlist.append(i.upper())

Read Input and Make Uppercase
In some cases we may need to get some input from the user interactively and then make this input uppercase and print to the standard output or store as uppercase.
while 2>1:
print('Enter your word')
i = input()
print(i.upper())
