Scripting

Python String Lower() and Upper()

Python String Lower() and Upper()

Introduction

The lower() function in Python converts a string to print out a string consisting of all lowercase characters. The upper() function in Python converts a string to print out a string consisting of all uppercase characters. These are useful functions to transform strings.

Now we will start introducing you to using the lower() and upper() functions in Python. Hope you understand.

Example

1. The lower() function

str = "HEllo"

x = str.lower()

print(x)

Output:
hello

2. The upper() function

str = "HEllo"

x = str.upper()

print(x)

Output:

HELLO

Definition

1. The lower() function

This converts a string with all lowercase.

2. The upper() function

This converts a string with all uppercase.

The syntax

1. The lower() function

string.lower()

2. The upper() function

string.upper()

Parameter Values:

No parameter.

More examples

Example 1: Converting a string to lowercase

print("Enter the string you want to convert:")

x = input().lower()

print("The converted string is:",x)

Output:

Enter the string you want to convert: HeLLo

The converted string is: hello

Example 2: Converting a string to uppercase

print("Enter the string you want to convert:")

x = input().upper()

print("The converted string is:",x)

Output:

Enter the string you want to convert: hello

The converted string is: HELLO

Conclusion

We introduced you to using the lower() and upper() functions in Python.

Thank you for reading!

Similar Posts