Home ยป Convert String to Lowercase or Uppercase in python

Convert String to Lowercase or Uppercase in python

In this example we will show you how to convert a string to uppercase or lowercase

We will convert the String to Lowercase using the lower function

We will convert the String to Uppercase using the upper function

Example 1

This python program allows the user to enter a string.

Next, we used a built-in string function called upper to convert all characters in a string to uppercase

myText1 = input("Please Enter your Own Text : ")

myText2 = myText1.upper()

print("\nOriginal = ", myText1)
print("Result = ", myText2)

When you run this you will see something like this depending on the text you enter

>>> %Run stringupper1.py
Please Enter your Own Text : This is A Test String

Original = This is A Test String
Result = THIS IS A TEST STRING

Example 2

This python program allows the user to enter a string.

Next, we used a built-in string function called lower to convert all characters in a string to lowercase

myText1 = input("Please Enter your Own Text : ")

myText2 = myText1.lower()

print("\nOriginal = ", myText1)
print("Result = ", myText2)

Run this and you will see the following depending on the text you enter

>>> %Run stringlower1.py
Please Enter your Own Text : This is A Test String

Original = This is A Test String
Result = this is a test string

Links

code is available at

https://github.com/programmershelp/maxpython/tree/main/code%20example/String%20examples

You may also like

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More