Articles → Python → List Comprehension In PythonList Comprehension In PythonIn this article, we will discuss the list comprehension in Python.Purpose List comprehension is a concise way of creating a list.Example Consider a scenario where you want to create a list. The simplest logic of implementing the logic is: -out = [] for x in range(1, 5): out.append(x) print(out)There is another way to do it using list comprehension. So, the above logic can be rewritten as: -out = [] out = [x for x in range(1,5)] print (out)Output Posted By - Karan Gupta Posted On - Monday, March 11, 2019 Query/Feedback Your Email Id** Subject* Query/Feedback Characters remaining 250**
out = [] for x in range(1, 5): out.append(x) print(out)
out = [] out = [x for x in range(1,5)] print (out)
Query/Feedback