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

<tfoot id='dE76x'></tfoot>

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

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

      <i id='dE76x'><tr id='dE76x'><dt id='dE76x'><q id='dE76x'><span id='dE76x'><b id='dE76x'><form id='dE76x'><ins id='dE76x'></ins><ul id='dE76x'></ul><sub id='dE76x'></sub></form><legend id='dE76x'></legend><bdo id='dE76x'><pre id='dE76x'><center id='dE76x'></center></pre></bdo></b><th id='dE76x'></th></span></q></dt></tr></i><div id='dE76x'><tfoot id='dE76x'></tfoot><dl id='dE76x'><fieldset id='dE76x'></fieldset></dl></div>
    1. 在 Python 命令行上定义函数时出现语法错误

      时间:2023-10-08

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

      <tfoot id='Sedua'></tfoot>
        • <bdo id='Sedua'></bdo><ul id='Sedua'></ul>

                <tbody id='Sedua'></tbody>
              <legend id='Sedua'><style id='Sedua'><dir id='Sedua'><q id='Sedua'></q></dir></style></legend>
                <i id='Sedua'><tr id='Sedua'><dt id='Sedua'><q id='Sedua'><span id='Sedua'><b id='Sedua'><form id='Sedua'><ins id='Sedua'></ins><ul id='Sedua'></ul><sub id='Sedua'></sub></form><legend id='Sedua'></legend><bdo id='Sedua'><pre id='Sedua'><center id='Sedua'></center></pre></bdo></b><th id='Sedua'></th></span></q></dt></tr></i><div id='Sedua'><tfoot id='Sedua'></tfoot><dl id='Sedua'><fieldset id='Sedua'></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 命令行上定义函数时出现语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:virtualenv v16.7.2 powershell activate 脚本:&quot;你必须 下一篇:Pyinstaller:警告:找不到库

                相关文章

                最新文章

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

                <legend id='UpULE'><style id='UpULE'><dir id='UpULE'><q id='UpULE'></q></dir></style></legend>
              • <tfoot id='UpULE'></tfoot>

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