How can I get around declaring an unused variable in a for loop?
No. As the Zen puts it: Special cases aren't special enough to break the rules. The special case being loops not using the items of the thing being iterated and the rule being that there's a "target" to unpack to.
You can, however, use _
as variable name, which is usually understood as "intentionally unused" (even PyLint etc. knows and respect this).
Add the following comment after the for loop on the same line:
#pylint: disable=unused-variable
for i in range(100): #pylint: disable=unused-variable
It turns out that using dummy*
(starting word is dummy) as the variable name does the same trick as _
. _
is a known standard and it would be better to use meaningful variable names. So you can use dummy
, dummy1
, dummy_anything
. By using these variable names PyLint
won't complain.
_
is a standard placeholder name for ignored members in a for-loop and tuple assignment, e.g.
['' for _ in myList]
[a+d for a, _, _, d, _ in fiveTuples]
BTW your list could be written without list comprehension (assuming you want to make a list of immutable members like strings, integers etc.).
[''] * len(myList)