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

      1. <tfoot id='ryN71'></tfoot>
      2. <legend id='ryN71'><style id='ryN71'><dir id='ryN71'><q id='ryN71'></q></dir></style></legend>
          <bdo id='ryN71'></bdo><ul id='ryN71'></ul>

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

        如何在 Python 中使用布尔值?

        时间:2023-09-01

          <legend id='JaVAD'><style id='JaVAD'><dir id='JaVAD'><q id='JaVAD'></q></dir></style></legend>
              <tbody id='JaVAD'></tbody>

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

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

                  本文介绍了如何在 Python 中使用布尔值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Python 是否真的包含布尔值?我知道你可以这样做:

                  Does Python actually contain a Boolean value? I know that you can do:

                  checker = 1
                  if checker:
                      #dostuff
                  

                  但我很迂腐,喜欢在 Java 中看到布尔值.例如:

                  But I'm quite pedantic and enjoy seeing booleans in Java. For instance:

                  Boolean checker;
                  if (someDecision)
                  {
                      checker = true;
                  }
                  if(checker)
                  {
                      //some stuff
                  }
                  

                  Python 中是否有布尔值之类的东西?我似乎在文档中找不到类似的东西.

                  Is there such a thing as a Boolean in Python? I can't seem to find anything like it in the documentation.

                  推荐答案

                  checker = None 
                  
                  if some_decision:
                      checker = True
                  
                  if checker:
                      # some stuff
                  

                  更多信息:http://docs.python.org/library/functions.html#bool

                  您的代码也可以工作,因为必要时 1 会转换为 True.实际上 Python 很久没有布尔类型了(就像在旧的 C 中一样),一些程序员仍然使用整数而不是布尔值.

                  Your code works too, since 1 is converted to True when necessary. Actually Python didn't have a boolean type for a long time (as in old C), and some programmers still use integers instead of booleans.

                  这篇关于如何在 Python 中使用布尔值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Python 如果有很多或以收缩形式 下一篇:Python - “if"中的逻辑评估顺序陈述

                  相关文章

                  <tfoot id='LMEYV'></tfoot>

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

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

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