fruits = ["apple", "banana", "cherry"]
for f in fruits:
print(f)
for i, f in enumerate(fruits):
print(i, f)
List Comprehensions (Pythonic way to build lists)
# Create a list of squares
squares = [x**2 for x in range(5)]
print(squares) # [0, 1, 4, 9, 16]
# Filter values
even_numbers = [x for x in range(10) if x % 2 == 0]
print(even_numbers) # [0, 2, 4, 6, 8]
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Defined with square brackets
[].Basic Operations
List Methods
Useful Built-in Functions with Lists
Iterating Over Lists
List Comprehensions (Pythonic way to build lists)
Summary: