+ 4

What is the use of comprehension in python

plz, let me know about comprehension,what it is actually???

13th Sep 2018, 3:31 AM
Saddam Khan Abuzaid
Saddam Khan Abuzaid - avatar
3 Réponses
+ 8
Comprehensions are the 'pythonic' way to create lists, sets or dictionaries. For example, to create a list containing the squares of 0-9, you can do the same thing as in every other programming language; create an empty list, iterate over the numbers 0-9 and append their squares to the list: squares = [] for i in range(10): squares.append(i**2) Or you can use a list comprehension and do everything in one step: squares = [i**2 for i in range(10)]
13th Sep 2018, 5:13 AM
Anna
Anna - avatar
+ 4
thank you so much
13th Sep 2018, 5:14 AM
Saddam Khan Abuzaid
Saddam Khan Abuzaid - avatar