DekGenius.com
PYTHON
python access index in for loop
for index, item in enumerate(items):
print(index, item)
#if you want to start from 1 instead of 0
for count, item in enumerate(items, start=1):
print(count, item)
for loop with index python3
colors = ["red", "green", "blue", "purple"]
for i in range(len(colors)):
print(colors[i])
python for loop with index
colors = ["red", "green", "blue", "purple"]
for i in range(len(colors)):
print(colors[i])
python for loop index
# Creates two variables; An index (num), and the value at that index (line)
for num, line in enumerate(lines):
print("{0:03d}: {}".format(num, line))
python loop index and value
l = ["val1", "val2","val3"]
for i, value in enumerate(l):
print(f'Index= {i}, value= {value}')
for loop with index python
presidents = ["Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson"]
for i in range(len(presidents)):
print("President {}: {}".format(i + 1, presidents[i]))
python loop with index
presidents = ["Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson"]
for num, name in enumerate(presidents, start=1):
print("President {}: {}".format(num, name))
print index in for loop python
for index, item in enumerate(items):
print(index, item)
© 2022 Copyright:
DekGenius.com