【问题标题】:Visual Studio Code Python Conditional Statement problem [duplicate]Visual Studio Code Python条件语句问题[重复]
【发布时间】:2020-06-23 19:18:59
【问题描述】:

您好,我是编程新手,目前正在通过 LinkedIn 学习 Python,但我一直停留在其中一个示例代码上

def main():
    a, b = 1, 10
    if(a < b):
        st = "x is LESSER than y"
    print(st)

它甚至没有显示任何错误消息,所以我现在很困惑。 (我的解释器是 Python 3.7.4)

【问题讨论】:

  • 你打电话给main()吗?
  • 对于简单的 if-boolean-expressions,不要使用大括号 (),这不是 Java/C++/JavaScript/C#

标签: python if-statement visual-studio-code


【解决方案1】:

你刚刚创建了一个函数。您需要调用该函数才能执行

【讨论】:

    【解决方案2】:

    除非绝对必要,否则您可以直接打印,而不是使用变量。 调用函数main()

    def main():
        a, b = 1, 10
        if a < b:
            print("a is LESSER than b")
    
    main()
    

    【讨论】:

      猜你喜欢
      • 2022-01-07
      • 2014-12-07
      • 2021-12-17
      • 2019-07-17
      • 2017-12-25
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      • 2016-02-06
      相关资源
      最近更新 更多