Loop structures: Difference between revisions

Content added Content deleted
(Fix comment)
(list comprehension)
Line 744: Line 744:
else:
else:
print 'all numbers are positive'
print 'all numbers are positive'

=== list comprehension ===

Typically used when you want to create a list and there is little logic involved. Faster then for loop:

positives = [n for n in numbers if n > 0]


===while===
===while===