Python print语句"语法错误:语法无效"

Joh*_*mBF 50 python syntax syntax-error python-3.x

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

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","")
Run Code Online (Sandbox Code Playgroud)

Python的版本是:

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

mik*_*obi 115

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


gng*_*ath 7

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

在Python 3中print "Hello world",语法错误无效.

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