1. <i id='fZ2JB'><tr id='fZ2JB'><dt id='fZ2JB'><q id='fZ2JB'><span id='fZ2JB'><b id='fZ2JB'><form id='fZ2JB'><ins id='fZ2JB'></ins><ul id='fZ2JB'></ul><sub id='fZ2JB'></sub></form><legend id='fZ2JB'></legend><bdo id='fZ2JB'><pre id='fZ2JB'><center id='fZ2JB'></center></pre></bdo></b><th id='fZ2JB'></th></span></q></dt></tr></i><div id='fZ2JB'><tfoot id='fZ2JB'></tfoot><dl id='fZ2JB'><fieldset id='fZ2JB'></fieldset></dl></div>

      <small id='fZ2JB'></small><noframes id='fZ2JB'>

    2. <tfoot id='fZ2JB'></tfoot><legend id='fZ2JB'><style id='fZ2JB'><dir id='fZ2JB'><q id='fZ2JB'></q></dir></style></legend>
      • <bdo id='fZ2JB'></bdo><ul id='fZ2JB'></ul>

      什么是真假?它与真假有什么不同?

      What is Truthy and Falsy? How is it different from True and False?(什么是真假?它与真假有什么不同?)

        <bdo id='VRgA8'></bdo><ul id='VRgA8'></ul>

        <small id='VRgA8'></small><noframes id='VRgA8'>

        <i id='VRgA8'><tr id='VRgA8'><dt id='VRgA8'><q id='VRgA8'><span id='VRgA8'><b id='VRgA8'><form id='VRgA8'><ins id='VRgA8'></ins><ul id='VRgA8'></ul><sub id='VRgA8'></sub></form><legend id='VRgA8'></legend><bdo id='VRgA8'><pre id='VRgA8'><center id='VRgA8'></center></pre></bdo></b><th id='VRgA8'></th></span></q></dt></tr></i><div id='VRgA8'><tfoot id='VRgA8'></tfoot><dl id='VRgA8'><fieldset id='VRgA8'></fieldset></dl></div>
            <tbody id='VRgA8'></tbody>
          <legend id='VRgA8'><style id='VRgA8'><dir id='VRgA8'><q id='VRgA8'></q></dir></style></legend>
          • <tfoot id='VRgA8'></tfoot>

                本文介绍了什么是真假?它与真假有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                I just learned there are truthy and falsy values in python which are different from the normal True and False.

                Can someone please explain in depth what truthy and falsy values are? Where should I use them? What is the difference between truthy and True values and falsy and False values?

                解决方案

                As the comments described, it just refers to values which are evaluated to True or False.

                For instance, to see if a list is not empty, instead of checking like this:

                if len(my_list) != 0:
                   print("Not empty!")
                

                You can simply do this:

                if my_list:
                   print("Not empty!")
                

                This is because some values, such as empty lists, are considered False when evaluated for a boolean value. Non-empty lists are True.

                Similarly for the integer 0, the empty string "", and so on, for False, and non-zero integers, non-empty strings, and so on, for True.

                The idea of terms like "truthy" and "falsy" simply refer to those values which are considered True in cases like those described above, and those which are considered False.

                For example, an empty list ([]) is considered "falsy", and a non-empty list (for example, [1]) is considered "truthy".

                See also this section of the documentation.

                这篇关于什么是真假?它与真假有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Split a Pandas column of lists into multiple columns(将 Pandas 的列表列拆分为多列)
                How does the @property decorator work in Python?(@property 装饰器在 Python 中是如何工作的?)
                What is the difference between old style and new style classes in Python?(Python中的旧样式类和新样式类有什么区别?)
                How to break out of multiple loops?(如何打破多个循环?)
                How to put the legend out of the plot(如何将传说从情节中剔除)
                Why is the output of my function printing out quot;Nonequot;?(为什么我的函数输出打印出“无?)

                    <legend id='bZME5'><style id='bZME5'><dir id='bZME5'><q id='bZME5'></q></dir></style></legend>
                      <bdo id='bZME5'></bdo><ul id='bZME5'></ul>
                        <tbody id='bZME5'></tbody>
                      1. <small id='bZME5'></small><noframes id='bZME5'>

                        <i id='bZME5'><tr id='bZME5'><dt id='bZME5'><q id='bZME5'><span id='bZME5'><b id='bZME5'><form id='bZME5'><ins id='bZME5'></ins><ul id='bZME5'></ul><sub id='bZME5'></sub></form><legend id='bZME5'></legend><bdo id='bZME5'><pre id='bZME5'><center id='bZME5'></center></pre></bdo></b><th id='bZME5'></th></span></q></dt></tr></i><div id='bZME5'><tfoot id='bZME5'></tfoot><dl id='bZME5'><fieldset id='bZME5'></fieldset></dl></div>
                        • <tfoot id='bZME5'></tfoot>