Search code examples
pythonpycharm

Explicitly declaring variable as unused in Python/PyCharm


Is there a way to declare a variable as unused in PyCharm, or in Python in general, so you can explicitly tell the compiler not to give a warning about it?

I am not talking about the convention of naming unused variables for the programmer (often named "_" or "__"), but an option to explicitly mark a variable as unused for the compiler, for example in a loop. I also don't just want to disable inspections in general.

I've heard that you can do this in PyDev by beginning the variable name with "unused", and I thought this might exist in PyCharm as well, but couldn't find it yet.


Solution

  • I've noticed that using a single underscore for the throwaway variable name seems to bypass this check. I'm using PyCharm 2016.1.3.

    for _ in range(3):
        pass