<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语句?

      If statement for strings in python?(python中字符串的if语句?)
      <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语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                How to extend Python class init(如何扩展 Python 类初始化)
                What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                Initialize list with same bool value(使用相同的布尔值初始化列表)
                setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)

              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>

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