【问题标题】:Python print statement “Syntax Error: invalid syntax” [duplicate]Python打印语句“语法错误:无效语法” [重复]
【发布时间】:2011-11-26 22:08:22
【问题描述】:

为什么 Python 在第 9 行的简单 print 语句中给我一个语法错误?

import hashlib, sys
m = hashlib.md5()
hash = ""
hash_file = raw_input("What is the file name in which the hash resides?  ")
wordlist = raw_input("What is your wordlist?  (Enter the file name)  ")
try:
    hashdocument = open(hash_file,"r")
except IOError:
    print "Invalid file."    # Syntax error: invalid syntax
    raw_input()
    sys.exit()
else:
    hash = hashdocument.readline()
    hash = hash.replace("\n","")

Python的版本是:

Python 3.2.2 (default, Sep  4 2011, 09:07:29) [MSC v.1500 64 bit (AMD64)] on win
32

【问题讨论】:

    标签: python python-3.x syntax syntax-error


    【解决方案1】:

    在 Python 3 中,print 是一个函数,你需要像 print("hello world") 这样调用它。

    【讨论】:

      【解决方案2】:

      使用print("use this bracket -sample text")

      在 Python 3 中,print "Hello world" 给出了无效的语法错误。

      要在 Python3 中显示字符串内容,必须使用 ("Hello world") 括号。

      【讨论】:

        猜你喜欢
        • 2014-02-27
        • 2023-04-06
        • 2014-04-29
        • 1970-01-01
        • 2014-11-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多