Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I satisfy the Unused Variable rule from PEP8 if I don't need a variable returned by a function?

Tags:

People also ask

How do you handle unused variables in Python?

To suppress the warning, one can simply name the variable with an underscore ('_') alone. Python treats it as an unused variable and ignores it without giving the warning message.

Should you delete unused variables in Python?

In general, don't worry about deleting variables. Python has garbage collection, so any objects that you can no longer access (usually because you've left their scope) will automatically be freed from memory, you don't have to worry about this at all.

Which of the following styles does pep8 recommend for multi word variable names?

As mentioned, PEP 8 says to use lower_case_with_underscores for variables, methods and functions.


When having a function in Python that returns a couple of variables, for example:

row, column = search_in_table(table_name, search_for)

Sometimes you only need to use one of the variables returned by the function. But when this happens, the line is marked with a PEP8 Unused Variable warning.

How can I handle this situation so I can comply with all the PEP8 rules?