When you want to perform an action a certain number of times without caring about the loop variable, the convention is to use an underscore (_
) instead of a named variable like i
. This signals to readers of your code: "I'm not going to use this variable."
So your questionable
function can be rewritten in a more Pythonic way like this:
def more_pythonic():
for _ in range(3):
print('Is this OK?')