简体   繁体   English

python shell 在运行 print() 时出现语法错误,但是在 jupytr notebook 中执行相同的代码

[英]python shell gives syntax error when running a print() ,however the same code executes in jupytr notebook

def test_number(x, y):
    if x == y or abs(x-y) == 5 or (x+y) == 5:
        return True
    else:
        return False

    print(test_number(7, 2))
    print(test_number(3, 2))
    print(test_number(2, 2))

When run in jupyter notebook, it executes with O/P:True when run in python shell cmd, it gives invalid syntax在 jupyter notebook 中运行时,在 python shell cmd 中运行时以 O/P:True 执行,它给出了无效的语法附上错误图片

Error is in the ident.错误在标识中。 Python is an ident base language. Python 是 ident 基础语言。 Correct example.正确的例子。

def test_number(x, y):
    return x == y or abs(x-y) == 5 or (x+y) == 5

print(test_number(7, 2))
print(test_number(3, 2))
print(test_number(2, 2))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 vs 代码的终端中运行 python 给我一个语法错误,但是,手动选择代码并运行它不会给我语法错误 - Running python in terminal in vs code gives me a syntax error, however, manually selecting the code and running it does not give me the syntax error 运行python 3代码时python 2语法错误 - python 2 syntax error when running python 3 code SyntaxError:语法无效(从shell运行python代码时) - SyntaxError: invalid syntax (when running python code from shell) jupyter notebook python版本2.7.13(打印无效语法错误) - jupyter notebook python version 2.7.13 (print invalid syntax error) 在 Jupyter 笔记本中运行 python selenium、WebDriverException 错误代码时收到错误消息? - Receiving error message when running python selenium, WebDriverException error code in Jupyter notebook? 如果我从 cmd 运行此代码,Python 会出错,但是如果我从 Jupyter 运行它,则运行良好 - Python gives error if I run this code from cmd, however runs fine if I run it from Jupyter Python Shell - 语法错误 - Python Shell - Syntax Error Python 脚本在从 Jenkins 运行时出现语法错误 - Python script gives Syntax error while running it from Jenkins 运行我的Python代码期间的语法错误 - Syntax error during running my Python code 在python shell中运行telnet时出现错误消息 - Error message when running telnet in python shell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM