Hello. First of all i'm compete newbie in the python. And second i was wondering for some time what does the value 'i" do in python or is it a value at all? I'm sorry if i'm pre-posting a question that have been answered already.

This is the example :


def drawBoard(board):

hline = ' '
for i in range(1, 6):
hline += (' ' * 9) + str(i)

print(hline)
print(' ' + ('0123456789' * 6))
print()

Thank you, and sorry for the stupid question i gues.

Sometimes you have to ask 'stupid' questions to get smarter!
We are glad to help.

In your case i is simply the name of a variable that holds the value as you iterate over a given range of numbers. You can use any allowed variable name, I usually use k since it is more visible to my old eyes.

# range(5) will iterate from 0 to 4 (excludes 5)
for k in range(5):
    print(k)

"""my result -->
0
1
2
3
4
"""
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.