Hit enter after type your search item

Python lower() and upper() functions of strings

Python has built-in functions for converting the case of all letters in a given string. These are functions are explained below.

Python lower() function

The lower() function is used to convert all cased characters to the lowercase. The Python lower() function returns a copy of the given string in which all cased letters are converted to lowercase.

A lower()example  upper() example()

Syntax of lower() function

This is how cased letters can be converted to lowercase:

Str.lower()

The Str can be any string that needs to be converted to lowercase.

An example of Python lowercase

In the following example, a string is created with all capital letters. This is followed by using the lower() function and the returned string is displayed by using the print function.

See online demo and code


Python lower

In the output, you can see all letters are lowercased. The second print function displays the original string that shows the string remains the same after using the lower() function; as such the strings are immutable.

An example of lower() with input function

For this example, the input function is used for taking the user input. As you enter a string and press enter (return), the lower() function will execute and if the entered string contained any capital letters, those will be converted to lowercase. Have a look:

See online demo and code


 

lowercase input

The upper() function

The upper() function returns a copy of given string with all the small case characters converted to upper case.

See this example where input function is used to get the user input just like the above example.

See online demo and code


upper

You can see, mixed letters entered and upper() function converted all small letters to the upper case letters. While, the original string remained the same, as such upper() function returns a copy of the string.

This div height required for enabling the sticky sidebar