I'm trying to clarify my understanding regarding situations in the code in which the singular seems to extract from the plural. I'm not sure if this is standard among different languages, or, unique to specific situations in python. Regardless, in the example below I refer to square within the squares list:
squares=['white', 'black', 'red', 'blue', 'green']
for i, square in enumerate(squares):
print(i, square)
0 white
1 black
2 red
3 blue
4 green
Is python intuitive enough to know I am referring to the singular square from the "squares" list? Is it unique to just this type of coding request or is it more broad and standard? etc.
The variables
squareandsquaresare completely unrelated. In this case, the use of the variablesquare(singular) is an arbitrary decision by the coder. I.e....would work identically had the coder chosen ...
The
enumeratemethod is a generator which iterates through a list, and yields each item in the list's index, and value in that order. By convention only, coders often chooseito stand forindexand will frequently give the list a plural name, and the variable intended to hold the value the singular of that plural.But it is entirely arbitrary and up to the coder's preferences what the variable's names are.