pthon3.3...print,出错的问题。。。。

刚开始学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(*objectssep=' 'end='\n'file=sys.stdoutflush=False)

Print objects to the stream file, separated by sep and followed by endsepend 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 Nonesys.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.html
print()。文档是这样写的: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!")



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章