How can I denote unused function arguments?

前端 未结 7 1776
梦谈多话
梦谈多话 2020-12-08 01:54

When \"deconstructing\" a tuple, I can use _ to denote tuple elements I\'m not interested in, e.g.

>>> a,_,_ = (1,2,3)
>>> a
1         


        
相关标签:
7条回答
  • 2020-12-08 02:22

    In order to avoid "unused variable" inspection messages for unused *args and/or **kwargs, I replace args and kwargs by _ and __ :

    def f(a, b, *_, **__):
        ...
    

    In addition to remove messages, it clearly shows that you don't care about these arguments.

    I can't say if it is a really universal solution, but it worked everywhere I've used it until now.

    0 讨论(0)
提交回复
热议问题