Convert String Lowercase to Uppercase in Python 3.9

Convert String Lowercase to Uppercase in Python 3.9

How to convert lowercase to uppercase in python?

In this post, we will demonstrate to you two ways to convert python strings (all letters) lowercase to uppercase. The first way is to convert lowercase to uppercase in python with using the function and the second way is how to convert lowercase to uppercase in python without using string function.

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.

Now we will 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

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 Convert String Lowercase to Uppercase in Python 3.9

  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 *