<bdo id='rVC15'></bdo><ul id='rVC15'></ul>
  1. <tfoot id='rVC15'></tfoot>

    <legend id='rVC15'><style id='rVC15'><dir id='rVC15'><q id='rVC15'></q></dir></style></legend>
  2. <small id='rVC15'></small><noframes id='rVC15'>

  3. <i id='rVC15'><tr id='rVC15'><dt id='rVC15'><q id='rVC15'><span id='rVC15'><b id='rVC15'><form id='rVC15'><ins id='rVC15'></ins><ul id='rVC15'></ul><sub id='rVC15'></sub></form><legend id='rVC15'></legend><bdo id='rVC15'><pre id='rVC15'><center id='rVC15'></center></pre></bdo></b><th id='rVC15'></th></span></q></dt></tr></i><div id='rVC15'><tfoot id='rVC15'></tfoot><dl id='rVC15'><fieldset id='rVC15'></fieldset></dl></div>
    1. raise 条件表达式上的语句

      raise statement on a conditional expression(raise 条件表达式上的语句)

        1. <small id='eFAu9'></small><noframes id='eFAu9'>

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

            <tfoot id='eFAu9'></tfoot>
                <bdo id='eFAu9'></bdo><ul id='eFAu9'></ul>
                本文介绍了raise 条件表达式上的语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                遵循武士原则",我正在尝试在我的功能上执行此操作,但似乎是错误的......

                Following "Samurai principle", I'm trying to do this on my functions but seems it's wrong...

                return <value> if <bool> else raise <exception>
                

                还有其他漂亮"的方法可以做到这一点吗?谢谢

                Is there any other "beautiful" way to do this? Thanks

                推荐答案

                内联/三元 if 是表达式,而不是语句.您的尝试意味着如果 bool,返回值,否则返回 raise 表达式 的结果" - 这当然是无稽之谈,因为 raise exception 本身就是一个语句而不是表达式.

                Inline/ternary if is an expression, not a statement. Your attempt means "if bool, return value, else return the result of raise expression" - which is nonsense of course, because raise exception is itself a statement not an expression.

                没有办法以内联方式执行此操作,您也不应该这样做.明确地这样做:

                There's no way to do this inline, and you shouldn't want to. Do it explicitly:

                if not bool:
                    raise MyException
                return value
                

                这篇关于raise 条件表达式上的语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)

                <small id='4Jdlh'></small><noframes id='4Jdlh'>

                      <tbody id='4Jdlh'></tbody>

                      <bdo id='4Jdlh'></bdo><ul id='4Jdlh'></ul>

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