How to Convert List to Lowercase in Django?

Published On: 30/07/2022 | Category: Django Python


Hi Dev,

Now, let's see article of django convert list values to lowercase. I explained simply step by step convert list to lowercase django. if you have question about convert list elements to lowercase python then I will give simple example with solution. I explained simply about convert list data to lowercase django. Alright, let’s dive into the steps.

There are many ways to convert list elements to lowercase in django. i will give you two examples using for loop with lower() to convert list data to lowercase. so let's see the below examples.

You can use these examples with django3 (django 3) version.

let's see below simple example with output:

Example : 1 views.py
from django.shortcuts import render
from django.http import HttpResponse

def index(request):

    myList = ['One', 'TWO', 'Three']
  
    # Convert List Value into lowercase
    for i in range(len(myList)):
        myList[i] = myList[i].lower()
      
    print(myList)
    
    return HttpResponse(myList)
Output
['one', 'two', 'three']
Example : 2 views.py
from django.shortcuts import render
from django.http import HttpResponse

def index(request):

    myList = ['One', 'TWO', 'Three']
  
    # Convert List Value into lowercase
    newList = [x.lower() for x in myList]
      
    print(newList)

    return HttpResponse(newList)
Output
['one', 'two', 'three']

I Hope It will help you....