2011-09-28 37 views
47

Tại sao Python cho tôi lỗi cú pháp tại câu lệnh print đơn giản trên dòng 9?Lệnh in Python “Cú pháp lỗi: cú pháp không hợp lệ”

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","") 

Các phiên bản của Python là:

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

Trả lời

107

Trong Python 3, in ấn là một chức năng, bạn cần phải gọi nó như print("hello world").

7

Sử dụng print("use this bracket -sample text")

Trong Python 3 print "Hello world" cho lỗi cú pháp hợp lệ.

Để hiển thị nội dung chuỗi trong Python3 phải sử dụng dấu ngoặc đơn ("Hello world") này.

Các vấn đề liên quan