美文网首页
第一个Python程序hello.py提示出现File &quo

第一个Python程序hello.py提示出现File &quo

作者: WSGNSLog | 来源:发表于2018-01-15 14:48 被阅读1845次

写第一个Python程序hello.py,内容仅有一句,print 'hello world',

运行hello.py 出错,提示:

>>> python hello.py
  File "<stdin>", line 1
    python hello.py
           ^
SyntaxError: invalid syntax

原因:

  在shell脚本中,运行shell脚本命令;在Python命令行中,运行Python代码。然而,“python hello.py”是一个脚本命令,不是python代码。

  因此,退出python命令行,直接cd到hello.py所在目录,运行python hello.py,即可。

   若是非要在python命令行中运行,输入print("hello world")即可。

参考:https://www.cnblogs.com/neuzjq/p/6417197.html

相关文章

网友评论

      本文标题:第一个Python程序hello.py提示出现File &quo

      本文链接:https://www.haomeiwen.com/subject/vgtdoxtx.html