How to Change a String to Lowercase in Python

With Python there are lots of ways you can manipulate strings. One of the most common I find myself using is to convert a string to lowercase, often before passing the string to another function. This can be useful with dealing with anything that is case sensitive. Luckily, its easy to change a string to lowercase in Python.

In Python we can use the lower() method on a string to change all the uppercase characters to lowercase. The lower() method doesn’t take in any parameters, and has the following syntax:

string.lower()

Let us take a look at an example.

If we had the string “HTTPS://BuildVirtual.Net“, we could use convert it to lowercase using the following Python code:

>>> text = 'HTTPS://BuildVirtual.Net'
>>> print(text.lower())
https://buildvirtual.net

As you can see, the string has been converted entirely to lowercase.

Another way to do this is to use the lower() method directly on the string, for example:

'HTTPS://BuildVirtual.Net'.lower()
'https://buildvirtual.net'

Or by using print:

print('HTTPS://BuildVirtual.Net'.lower())
https://buildvirtual.net

A short article, but you should now know a few ways to change a string to lowercase using Python!

Related posts

Docker Exec Command With Practical Examples

Debugging with Git Bisect

A Beginners Guide to Azure Repos

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