Iterate a certain number of times without storing the iteration number anywhere [duplicate]
The idiom (shared by quite a few other languages) for an unused variable is a single underscore _
. Code analysers typically won't complain about _
being unused, and programmers will instantly know it's a shortcut for i_dont_care_wtf_you_put_here
. There is no way to iterate without having an item variable - as the Zen of Python puts it, "special cases aren't special enough to break the rules".
exec 'print "hello";' * 2
should work, but I'm kind of ashamed that I thought of it.
Update: Just thought of another one:
for _ in " "*10: print "hello"