enumerate function

l1 = ["potato", "tomato", "egg roll", "chatpati", "rice"]
i = 0
for item in l1:
if i % 2 == 0:
print(f"pls bring this items only {item}")
i += 1

# this is short method of upper code using enumerate function
for index, item in enumerate(l1):
if index % 2 == 0:
print(f"pls bring this item only {item}")

Comments

Popular posts from this blog

Steps taken by a compiler to execute a C program

Tokens in C

Variables and Data Types in C