這是爲什麼抱怨無效的語法?爲什麼這是無效的語法?
#! /usr/bin/python
recipients = []
recipients.append('[email protected]')
for recip in recipients:
print recip
我不斷收到:
這是爲什麼抱怨無效的語法?爲什麼這是無效的語法?
#! /usr/bin/python
recipients = []
recipients.append('[email protected]')
for recip in recipients:
print recip
我不斷收到:
如果它是Python 3,print
現在是一個函數。正確的語法是
print (recip)
在python 3中,print不再是一個語句,而是一個function。
Old: print "The answer is", 2*2
New: print("The answer is", 2*2)
更多蟒蛇3 print
功能:
Old: print x, # Trailing comma suppresses newline
New: print(x, end=" ") # Appends a space instead of a newline
Old: print # Prints a newline
New: print() # You must call the function!
Old: print >>sys.stderr, "fatal error"
New: print("fatal error", file=sys.stderr)
Old: print (x, y) # prints repr((x, y))
New: print((x, y)) # Not the same as print(x, y)!
重複:http://stackoverflow.com/questions/826948/python-syntax-error-on-print – 2009-12-07 20:04:47