How to Convert String Lowercase to Uppercase in Python

How to Convert String Lowercase to Uppercase in Python

Convert all lowercase letters to uppercase letters in python; Through this tutorial, you will learn how to convert all lowercase letters to uppercase letters or characters or string in python.

Python has many built-in functions/methods for manipulation with strings, which you can check here (python string methods).

1: Convert lowercase to uppercase in python with using the function

You can use the python string method/function that name upper(), This method converts all letters or characters of string lowercase to uppercase.

The syntax of upper() method is:

string.upper()

String upper() Parameters()

The upper() method doesn’t take any parameters.

Return value from String upper()

The upper() method returns the uppercased string from the given string. It converts all lowecase characters to uppercase.

If no lowercase characters exist, it returns the original string.

Example 1: write a program to convert all lowercase to uppercase characters in python

# example string
string = "This is first example of convert string lowercase to uppercase"
print(string.upper())

#Output
#THIS IS FIRST EXAMPLE OF CONVERT STRING LOWERCASE TO UPPERCASE

2: How to convert lowercase to uppercase in python without using string function

As you have seen in the example given above, we have done how to convert all the letters of string from lowercase to uppercase by using the upper() method of Python.

To write a program in Python that will convert all the letters of the string from lowercase to uppercase without using any Python function:

# convert lowercase to uppercase in python without using function
st = 'how to convert lowercase to uppercase in python without using string function'
out = ''
for n in st:
    if n not in 'abcdefghijklmnopqrstuvwqxyz':
        out = out + n
    else:
        k = ord(n)
        l = k - 32
        out = out + chr(l)
print('------->', out)   

The output of above python program is:

HOW TO CONVERT LOWERCASE TO UPPERCASE IN PYTHON WITHOUT USING STRING FUNCTION

Recommended Python Tutorials

  1. Python Program to Convert Uppercase to Lowercase
  2. Python First Character of String Uppercase
  3. Python Concatenate String and Variable (int, float, etc)
  4. How to Find Length of String in Python
  5. Python: String Join Function
  6. Python String Append Examples
  7. How to replace a character in a string in python
  8. Python – Count Number of Occurrences in String
  9. Python Remove Last Character from String
  10. Python Remove Character From String
  11. Python Program to Reverse String
  12. Python Program to Remove First Occurrence of Character in a String
  13. Python: Remove Special Characters from String
  14. Python Program Count vowels in String
  15. Python Split a String into Array of Characters, Space
  16. Python Program to Swap Two Character of Given String
  17. Python Program String Find
  18. Python: Two Given Strings and Swap First Two Characters of Each String
  19. Print All Permutations of Given String in Python
  20. Python | Check Whether a String Contains Number or Letter
  21. Python: Convert String to Float & Float to String
  22. Python Program to Reverse String Using Stack
  23. How To Convert Python Int to String and String to Int
  24. Python Convert String to List and List to String

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

One reply to How to Convert String Lowercase to Uppercase in Python

  1. It was good to learn from this website, But it would have been great if you have provided a video for better understanding of the concept….

Leave a Reply

Your email address will not be published. Required fields are marked *