Python program to convert lowercase to uppercase | The writing systems that distinguish between the upper and lowercase have two parallel sets of letters, with each letter in one set usually having an equivalent in the other set. Lowercase letters are the shorter, smaller versions of letters (like w), as opposed to the bigger, taller versions (like W), which are called uppercase letters.
Uppercase letters are also known as capital letters. Uppercase letters signal to the reader that something is important or significant. English alphabet uppercase letters: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z.
In writing, most letters are lowercase. Lowercase letters are all letters that do not begin a sentence or refer to a proper noun. English alphabet lowercase letters: a b c d e f g h i j k l m n o p q r s t u v w x y z.
String to Uppercase in Python
This python program using the built-in function to convert lowercase to uppercase. We will take a string while declaring the variables. Then, the upper() function converts all lowercase characters in a string into uppercase characters and returns it. Finally, print the uppercase string.
The syntax of upper() method is:
The upper() method doesn’t take any parameters.
Return value from string upper():
The upper() function returns an uppercased string of the given string. If no lowercase characters exit, it returns the original string.
# Python program to convert lowercase to uppercase #take input string = input('Enter any string: ') # upper() function to convert lowercase to uppercase print('In Upper Case:', string.upper())
Output for the different input values:-
Enter any string: know program
In Upper Case: KNOW PROGRAM
Enter any string: Convert Lowercase to Uppercase
In Upper Case: CONVERT LOWERCASE TO UPPERCASE
Enter any string: python3
In Upper Case: PYTHON3
Convert Lowercase to Uppercase in Python Without using Function
In this program, we used For Loop to iterate characters. we are using the If Else Statement inside the for loop to check the character is between a and z or not. If the condition true, we are subtracting 32 from its ASCII value. Otherwise, we are coping that character to string 1. The ord() method is used to find the Unicode value of a character passed as its argument. The chr() method is used to find the character corresponding to the Unicode value passed as its argument.
# Python program to convert lowercase to uppercase # take input string = input('Enter any string: ') # convert lowercase to uppercase new_string ='' for i in range(len(string)): if(string[i] >= 'a' and string[i] <= 'z'): new_string = new_string + chr((ord(string[i]) - 32)) else: new_string = new_string + string[i] # print uppercase string print('In Upper Case:',new_string)
Enter any string: PYTHON program
In Upper Case: PYTHON PROGRAM
Uppercase Python using ASCII values
This python program also performs the same task but in a different way. We are comparing the ASCII values to check whether there are any lowercase characters in this string. If true, we are converting them to uppercase.
# Python program to convert lowercase to uppercase # take input string = input('Enter any string: ') # convert lowercase to uppercase new_string ='' for i in string: if(ord(i) >= 97 and ord(i) <= 122): new_string = new_string + chr((ord(i) - 32)) else: new_string = new_string + i # print uppercase string print('In Upper Case:',new_string)
Enter any string: upperCASE String
In Upper Case: UPPERCASE STRING
Also See:- Python program to check vowel or consonant
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or you find anything incorrect? Let us know in the comments. Thank you!