剛開始學python,跟這書上打個hello world 結果出錯了。。。。
python
print'hello'
File "<stdin>",line 1 print 'hello' SyntaxError:invalid syntax
>>> print 'hello'
File "<stdin>", line 1
print 'hello'
^
SyntaxError: invalid syntax
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)Print objects to the stream file, separated by sep and followed by end. sep, end and file, if present, must be given as keyword arguments.
All non-keyword arguments are converted to strings like str() does and written to the stream, separated by sep and followed by end. Both sep andend must be strings; they can also be None, which means to use the default values. If no objects are given, print() will just write end.
The file argument must be an object with a write(string) method; if it is not present or None, sys.stdout will be used. Whether output is buffered is usually determined by file, but if the flush keyword argument is true, the stream is forcibly flushed.
Changed in version 3.3: Added the flush keyword argument.
原來,print語句在3.0後已經被換成和print()函數,具體用法見上方的官方說明 查看3.0文檔:http://docs.python.org/release/3.0.1/whatsnew/3.0.htmlprint()。文檔是這樣寫的:The print statement has been replaced with a print() function, with keyword arguments to replace most of the special syntax of the old print statement (PEP 3105).
print語句被print()方法代替,舊print語句中的特定的語法被參數代替。
所以呢,hello world!應該寫成這樣:print ("hello world!")