Python convert string to lowercase1/17/2024 ![]() ![]() In the above code, three users are trying to register on the website. #Real time application of upper() in python The login ID must be stored in the uppercase version only and no two users should have the same login ID. It stores the login IDs only if the following conditions are satisfied: Real-time application of the upper() functionĬonsider an eCommerce website that stores the login ID of the users in its database. One of the applications of the upper() function is to check whether two strings that are formatted in different ways are actually the same or not. Here, the string contains a question mark which is left as it is in the output string. In the above code, we have taken a text string as an input from the user and used the upper() function to convert the string to the Uppercase version. Simple example of upper() function #Converting string to Uppercase using upper() function ![]() The function converts only lowercase characters to uppercase and leaves digits and other special characters as it is.The upper() function does not take any arguments and thus if you try to insert any parameters in the function then it gives an Exception.Since converting all characters of a string to uppercase without using a function can be a tedious task, we can use an in-built function called upper() in python which takes a string as an input and returns the output string with all of its characters converted into the uppercase format. Converting all characters to Uppercase using the upper() function Thus the character in lowercase can be successfully converted to Uppercase. We then use the chr() function to convert the Unicode value back to its character format.įor example, if the character is ‘a’ then ord(‘a’)=97, b=97-32 =65 and chr(65)=’A’. We use the ord() function to convert the character into its Unicode value and subtract 32 from it to get the Unicode value of its corresponding Uppercase character. Else if the character is present in the string, it means that it is a lowercase character. ![]() If the character is not present in the string, then we simply append the character to the output string. We check if the character is present in the string that contains all lowercase characters from. Then we use a for loop and iterate over every character of the text string. output: To store the resultant UpperCase string.In the above code, we initialize two variables The resultant UpperCase String is: HELLO FROM CODESPEEDY! Output: Enter string: hello From cOdeSpeedy! Print(f"The resultant UpperCase String is: ") Converting all characters to Uppercase without using the in-built Function # Converting string to Uppercase without using inbuilt function Also, you will understand the application of converting characters of a string to Uppercase with the help of a real-time example. We shall convert the string to Uppercase by using in-built functions in python as well as without using any in-built function with the help of a few examples. This tutorial will help you to understand the different ways of converting all characters of a string to Uppercase in Python. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |