Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do you make a For loop when you don't need index in python?

If I need a for loop in Python:

for i in range(1,42):
    print "spam"

but don't use the i for anything, pylint complains about the unused variable. How should I handle this? I know you can do this:

for dummy_index in range(1,42):
    print "spam"

but doing this seems quite strange to me. Is there a better way?

I'm quite new to Python, so forgive me if I'm missing something obvious.

like image 635
Jacxel Avatar asked Apr 12 '12 10:04

Jacxel


1 Answers

for _ in range(1,42):
    print "spam"
like image 196
jamylak Avatar answered Sep 17 '22 16:09

jamylak