• <tfoot id='21RH0'></tfoot>

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

      <small id='21RH0'></small><noframes id='21RH0'>

        在 Python 命令行上定义函数时出现语法错误

        Syntax error when defining a function on the Python command line(在 Python 命令行上定义函数时出现语法错误)
        <legend id='JXSjO'><style id='JXSjO'><dir id='JXSjO'><q id='JXSjO'></q></dir></style></legend>

          <tbody id='JXSjO'></tbody>

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

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

              1. <tfoot id='JXSjO'></tfoot>
                <i id='JXSjO'><tr id='JXSjO'><dt id='JXSjO'><q id='JXSjO'><span id='JXSjO'><b id='JXSjO'><form id='JXSjO'><ins id='JXSjO'></ins><ul id='JXSjO'></ul><sub id='JXSjO'></sub></form><legend id='JXSjO'></legend><bdo id='JXSjO'><pre id='JXSjO'><center id='JXSjO'></center></pre></bdo></b><th id='JXSjO'></th></span></q></dt></tr></i><div id='JXSjO'><tfoot id='JXSjO'></tfoot><dl id='JXSjO'><fieldset id='JXSjO'></fieldset></dl></div>
                  本文介绍了在 Python 命令行上定义函数时出现语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在 Python REPL 上定义一个函数.每次我尝试运行以下代码时,都会出现语法错误.

                  代码:

                  def hello():打印(你好!")你好()

                  错误:

                  C:Users~Desktop>pythonPython 3.6.5(v3.6.5:f59c0932b4,2018 年 3 月 28 日,16:07:46)[MSC v.1900 32 位(英特尔)] 在 win32 上输入帮助"、版权"、信用"或许可"以获取更多信息.>>>定义你好():...打印(你好!")... 你好()文件<stdin>",第 3 行你好()^SyntaxError:无效的语法

                  我在 stackoverflow 上遇到的一个可能的解释是这篇文章

                  I am trying to define a function on the Python REPL. Every time I try to run the below code, I get a syntax error.

                  Code:

                  def hello():
                      print ("Hello!")
                  hello()
                  

                  Error:

                  C:Users~Desktop>python
                  Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32
                  Type "help", "copyright", "credits" or "license" for more information.
                  >>> def hello():
                  ...     print ("Hello!")
                  ... hello()
                    File "<stdin>", line 3
                      hello()
                          ^
                  SyntaxError: invalid syntax
                  

                  A possible explanation I've come across on stackoverflow is this post Python Error : File "<stdin>" where it says I can't run scripts from the Python interpreter. If that's true, why is that the case? I.e. if I'm able to run >>>2+2 in the cmd window, why am I not able to run a 'def' function? Hoping to look for clarification on this point - Thanks!

                  Edit: Put the error in text, not just the pic.

                  解决方案

                  Press enter once after defining your function (that is, enter one blank line). Essentially, this lets Python know that you are done defining your function.

                  Once you see >>> again, you can call your function.

                  See the picture for how it should look when done right:

                  这篇关于在 Python 命令行上定义函数时出现语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Kivy 1.9.0 Windows package KeyError: #39;rthooks#39;(Kivy 1.9.0 Windows 包 KeyError: rthooks)
                  Python Kivy: how to call a function on button click?(Python Kivy:如何在按钮单击时调用函数?)
                  How to disable a widget in Kivy?(如何禁用 Kivy 中的小部件?)
                  Centering an object in Kivy(在 Kivy 中将对象居中)
                  How to downgrade to Python 3.4 from 3.5(如何从 Python 3.5 降级到 Python 3.4)
                  Change button or label text color in kivy(在kivy中更改按钮或标签文本颜色)

                  • <bdo id='III64'></bdo><ul id='III64'></ul>
                    • <small id='III64'></small><noframes id='III64'>

                        <tbody id='III64'></tbody>

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