#5, First Floor, 4th Street , Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

What is list comprehension in python?
Description

To know about the list comprehension
concept in python3.

Process

List comprehension:

   As list comprehension returns list, theyconsists of brackets containing the expression which needs to be executed for eachelement along with the for loop to iterate over each element.

   List comprehensions are used forcreating new list from another iterables.

Syntax:

[expression for loop one_or_more conditions]

Sapmle Code

#simple list
list1=[2,4,5,7]
print(“old list is\n”,list1)

#list comprehension
new_list1=[i*i for i in list1]

#printing new list
print(“New list is”)
print(new_list1)

Screenshots