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

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

    • <bdo id='hjjLY'></bdo><ul id='hjjLY'></ul>
    <legend id='hjjLY'><style id='hjjLY'><dir id='hjjLY'><q id='hjjLY'></q></dir></style></legend>

    <tfoot id='hjjLY'></tfoot>

      python中字符串的if语句?

      时间:2023-08-29
      <tfoot id='PwGV9'></tfoot>

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

          <bdo id='PwGV9'></bdo><ul id='PwGV9'></ul>
          1. <legend id='PwGV9'><style id='PwGV9'><dir id='PwGV9'><q id='PwGV9'></q></dir></style></legend>
              <tbody id='PwGV9'></tbody>

              1. <i id='PwGV9'><tr id='PwGV9'><dt id='PwGV9'><q id='PwGV9'><span id='PwGV9'><b id='PwGV9'><form id='PwGV9'><ins id='PwGV9'></ins><ul id='PwGV9'></ul><sub id='PwGV9'></sub></form><legend id='PwGV9'></legend><bdo id='PwGV9'><pre id='PwGV9'><center id='PwGV9'></center></pre></bdo></b><th id='PwGV9'></th></span></q></dt></tr></i><div id='PwGV9'><tfoot id='PwGV9'></tfoot><dl id='PwGV9'><fieldset id='PwGV9'></fieldset></dl></div>
                本文介绍了python中字符串的if语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我是一个完全的初学者,并且一直在查看 http://en.wikibooks.org/wiki/Python_Programming/Conditional_Statements 但我无法理解这里的问题.这很简单,如果用户输入 y 它应该打印这将进行计算,尽管我在 IF answer=="y"

                I am a total beginner and have been looking at http://en.wikibooks.org/wiki/Python_Programming/Conditional_Statements but I can not understand the problem here. It is pretty simple, if the user enters y it should print this will do the calculation although I get a syntax error on IF answer=="y"

                answer = str(input("Is the information correct? Enter Y for yes or N for no"))
                proceed="y" or "Y" 
                If answer==proceed:
                print("this will do the calculation"):
                else:
                exit()
                

                推荐答案

                即使您修复了代码中错误大小写的 if 和不正确的缩进,它也不会像您预期的那样工作.要根据一组字符串检查一个字符串,请使用 in.以下是你的做法(注意 if 都是小写,if 块中的代码缩进一级).

                Even once you fixed the mis-cased if and improper indentation in your code, it wouldn't work as you probably expected. To check a string against a set of strings, use in. Here's how you'd do it (and note that if is all lowercase and that the code within the if block is indented one level).

                一种方法:

                if answer in ['y', 'Y', 'yes', 'Yes', 'YES']:
                    print("this will do the calculation")
                

                另一个:

                if answer.lower() in ['y', 'yes']:
                    print("this will do the calculation")
                

                这篇关于python中字符串的if语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何检查 str(variable) 是否为空? 下一篇:如何迭代 pandas 数据框并创建新列

                相关文章

              2. <tfoot id='qsOWZ'></tfoot>

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

                  <legend id='qsOWZ'><style id='qsOWZ'><dir id='qsOWZ'><q id='qsOWZ'></q></dir></style></legend>

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

                  • <bdo id='qsOWZ'></bdo><ul id='qsOWZ'></ul>