美文网首页
What does _ mean in Python

What does _ mean in Python

作者: lixiaoquan | 来源:发表于2018-10-26 10:52 被阅读0次

    If you come from C/C++, you may be confused about the standalone _ in Python code. It actually acts as a temp variable which can be used later. That's it.

    But most of time, it is used because we don't care its value later. For example, there is a function which returns two values, and we only are interested in the second return value. At the mean time, we don't want to create a variable because naming a variable is boring and may causes 'Not used variable' warning.

    def func():
        return 1, 2
    
    _, x = func()
    

    相关文章

      网友评论

          本文标题:What does _ mean in Python

          本文链接:https://www.haomeiwen.com/subject/ojrktqtx.html