How to Convert List to Uppercase in Django?
Published On: 13/08/2022 | Category:
Django

Hi Dev,
In this example, I will show you django convert list values to uppercase. This article goes in detailed on convert list to uppercase python. you will learn convert list elements to uppercase django. you will learn convert list data to uppercase django. Let's get started with how to convert list to uppercase in django.
There are many ways to convert list elements to uppercase in django. i will give you two examples using for loop with upper() to convert list data to uppercase. so let's see the below examples.
You can use these examples with django3 (Django 3) version.
let's see below a simple example with output:
Example : 1 views.pyfrom django.shortcuts import render from django.http import HttpResponse def index(request): myList = ['One', 'two', 'Three'] # Convert List Value into uppercase for i in range(len(myList)): myList[i] = myList[i].upper() 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 uppercase newList = [x.upper() for x in myList] print(newList) return HttpResponse(newList)Output
['ONE', 'TWO', 'THREE']
I Hope It will help you....