JIYIK CN >

Current Location:Home > Learning > PROGRAM > Python >

Convert a list to lowercase in Python

Author:JIYIK Last Updated:2025/05/05 Views:

Lists can be used to store multiple items in a single variable. In Python, we can create a list of strings by enclosing the different elements in the list in single or double quotes.

This tutorial demonstrates how to convert a list of strings to lowercase in Python.


Convert a list of strings to lowercase in Python using str.lower()the function and loopfor

str.lower()Method is used to simply convert all the uppercase characters in a given string to lowercase characters and provide the result. Similarly, str.upper()method is used to reverse this process.

Apart from str.lower()the function, forloop is also used to iterate over all the elements in a given list of strings.

The following code uses str.lower()the function and fora loop to convert a list of strings to lowercase.

s = ["hEllO", "iNteRneT", "pEopLe"]
for i in range(len(s)):
    s[i] = s[i].lower()
print(s)

Output:

['hello', 'internet', 'people']

map()Convert a list of strings to lowercase using the function in Python

Python provides a map()function that can be used to apply a specific process between given elements in any specified iterable object; this function returns an iterator itself as output.

A lambda function can be defined as a compact anonymous function that accepts any number of arguments and contains only one expression. In this method, lambda functions will also mapbe used with functions.

The following code uses map()the function and lambda function to convert a list of strings to lowercase in Python.

s = ["hEllO", "iNteRneT", "pEopLe"]
a = map(lambda x: x.lower(), s)
b = list(a)
print(b)

Output:

['hello', 'internet', 'people']

Convert a list of strings to lowercase using list comprehension in Python

List comprehension is a shorter way to create a list to be formed based on given values ​​of an existing list. This method basically creates a new list where all items are lowercase.

The following code uses list comprehension to convert a list of strings to lowercase.

s = ["hEllO", "iNteRneT", "pEopLe"]
a = [x.lower() for x in s]
print(a)

Output:

['hello', 'internet', 'people']

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Remove all occurrences of an element from a Python list

Publish Date:2025/05/08 Views:69 Category:Python

In Python, lists allow the same element to appear multiple times. Even though the value of an element may be the same as other elements, each element will have a different index. Using these index numbers, you can easily access any element

Convert hex to bytes in Python

Publish Date:2025/05/08 Views:101 Category:Python

Hexadecimal, often abbreviated to hex, uses 16 symbols (0-9, a-f) to represent values, in contrast to the decimal system's 10. For example, 1000 in decimal is 3E8 in hexadecimal. Being proficient in dealing with hexadecimal is essential for

b in front of string in Python

Publish Date:2025/05/08 Views:53 Category:Python

This tutorial will discuss the statement in Python b" . b" Using the statement in Python b" The notation is used to specify strings in Python bytes . In contrast to regular strings with ASCII characters, bytes a string is an array of byte v

How to Convert Integer to Binary in Python

Publish Date:2025/05/08 Views:130 Category:Python

This tutorial explains how to convert an integer to binary in Python. This tutorial also lists some sample codes to illustrate different ways of converting from int to binary in Python. bin() Convert Int to Binary in Python using In Python,

How to convert an integer to bytes

Publish Date:2025/05/08 Views:77 Category:Python

Converting an integer int to a byte bytes is the inverse of bytes converting a byte to an integer . Most of the to methods int described in this article are the inverse of the to methods. int bytes bytes int Generic method for converting in

How to convert bytes to int in Python

Publish Date:2025/05/08 Views:111 Category:Python

Bytes The data type has a numerical range of 0~255 (0x00~0xFF). A byte has 8 bits of data, that's why its maximum value is 0xFF. In some cases, you need to convert a byte or byte array to an integer for further data processing. Let's see ho

How to Remove Punctuation from a String in Python

Publish Date:2025/05/08 Views:190 Category:Python

This tutorial discussed methods for removing punctuation from strings in Python. This is a particularly useful step when preprocessing and cleaning text data for NLP. string Remove punctuation from a string in Python using class methods We

How to Convert an Integer to a String in Python

Publish Date:2025/05/08 Views:69 Category:Python

This article will show you different ways to convert an integer to a string using Python code, such as str() the function and the f format method. str() Convert integer to string in Python using function We can use the inbuilt function in P

How to Replace Multiple Characters in a String in Python

Publish Date:2025/05/08 Views:97 Category:Python

This tutorial showed you how to replace multiple characters in a string in Python. Suppose we want to remove special characters from a string and replace them with spaces. The list of special characters to remove is !#$%^*() . Additionally,

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial